Saturday, 18 May 2013

Insertion of an element at last of array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10]={1,2,3,4,5};
int n;
printf("\nAt present elements of array are");
for(int i=0;i<=4;i++)
{
printf("\n%d",a[i]);
}
printf("\nEnter the element you want to insert");
scanf("%d",&n);
a[i]=n;
printf("\n New array after insertion is");
for(i=0;i<=5;i++)
{
printf("\n%d",a[i]);
}
getch();
}

Thursday, 16 May 2013

Calculate number of students having marks more than 60


#include<stdio.h>
#include<conio.h>
void main()
{
int marks[10],i,n=0,m;
clrscr();
printf("CALCULATE NUMBER OF STUDENTS HAVING MARKS >60");

for(i=0;i<=9;i++)
{
printf("\nEnter marks of student number %d",i+1);
scanf("%d",&marks[i]);
}
for(i=0;i<=9;i++)
{
if(marks[i]>60)
{
n++;
}
}
printf("\nNumber of students having marks more than 60 are : %d",n);
getch();
}

Accessing array elements using base address


#include<stdio.h>
#include<conio.h>
void main()
{
int data[5]={1,2,3,4,5};
int i;
int *base_add;
base_add=data;
clrscr();
printf("\t ACCESSING ARRAY ELEMENT USING BASE ADDRESS\N");
printf("\nHere base address is %u",base_add);
for(i=0;i<=4;i++)
{
printf("\nAt address= %u",base_add);
printf("\nWe have data[%d] i.e %d",i,*base_add);
base_add++;
}
getch();
}

Traversing an Array

Traversing an array means to access each and very element of array .It can be accessed using for loops.The data stored in array can be travesred by using for loop and the elements can be accessed by incerement the for loop. The loop starts to traverse array from the start of the array and continue to traverse array until the for lopp continues its execution until the for loop ends.UIn the program below the elements are stored in an array and are travesred using for loop . The loop prints all the elements of array using traversing.
 

Program for traversing an array.

#include<iostream.h>
#include<conio.h>
void main()
{
int data[5]={1,2,3,4,5};
int i;
clrscr();
cout<<""Elements of array Data are";
for(i=0;i<=4;i++)
{
cout<<data[i];
}
getch();
}

 

Find average of two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,average;
cout<<"Enter two numbers";
cin>>a>>b;
average=(a+b)/2;
cout<<"\n Average of two numbers is"<<average;
getch();
}

Wednesday, 15 May 2013

A simple "Hello World" program

#include<iostream.h>  //Header file
#include<conio.h>
void main()                // main function
{
cout<<"Hello World";
getch();
}



See also:
Find average of two numbers


                                          

Swapping value of two variables without third variable


#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<"enter the value of a";
cin>>a;
cout<<"\n Enter b";
cin>>b;  
a=a+b;  
b=a+b;  

a=b-a;    
b=-1*(a-b)-a;

cout<<"\n a is"<<a;
cout<<"\n b is"<<b;
getch();
}

full details in json
Proudly Powered by Blogger.
back to top