Friday, 14 September 2012

Array in C++

This is a new post about the important concept of C++ Programming : - ARRAY


//WRITE A PROGRAM TO ENTER TEN NUMBERS IN AN ARRAY AND DISPLAY THEM
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[10],i;
cout<<"Enter Ten numbers in an array"<<endl;
for(i=0;i<10;i++)
{
cin>>arr[i];
}
cout<<"The array elements are "<<endl;
for(i=0;i<10;i++)
{
cout<<arr[i]<<endl;
}
getch();
}


//WRITE A PROGRAM TO ENTER TEN NUMBERS IN AN ARRAY AND DISPLAY THEIR SUM
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[10],i,sum=0;
cout<<"Enter Ten numbers in an array"<<endl;
for(i=0;i<10;i++)
{
cin>>arr[i];
sum=sum+arr[i];
}
cout<<"The sum is "<<sum<<endl;
getch();
}


//WRITE A PROGRAM TO ENTER TEN NUMBERS IN AN ARRAY AND DISPLAY THE BIGGEST OF THEM
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[10],i,big=0;
cout<<"Enter Ten numbers in an array"<<endl;
for(i=0;i<10;i++)
{
cin>>arr[i];
if(arr[i]>big)
big=arr[i];

}
cout<<"The biggest number is "<<big<<endl;
getch();
}


//WRITE A PROGRAM TO ENTER TEN NUMBERS IN AN ARRAY AND DISPLAY THE SMALLEST OF THEM
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[10],i,small;
small=arr[0];
cout<<"Enter Ten numbers in an array"<<endl;

for(i=1;i<10;i++)
{
cin>>arr[i];
if(arr[i]<small)
small=arr[i];

}
cout<<"The smallest number is "<<small<<endl;
getch();
}

2 comments:

  1. sir plz update some basic regarding c++ for begnners

    ReplyDelete
  2. pls add some programs based on array of structure

    ReplyDelete