DESCRIPTION-: This program calculate the greatest number in the given array.In this we firstly enter the elements of an array and after entering the elements of an array the program finds the greatest element in array and produces output contain the largest number in the array.
FOR EXAMPLE-: If we enter elements of array as--------
2 34 1 67 99 45 33
Then program produces output as---------
gretest number in array is 99
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[10];
cout<<"enter number of elements in array";
cin>>n;
cout<<"enter the value of array elements"<<"\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n value of elements of array are";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
int max=a[0];
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
cout<<"largest number is"<<max;
getch();
}
FOR EXAMPLE-: If we enter elements of array as--------
2 34 1 67 99 45 33
Then program produces output as---------
gretest number in array is 99
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[10];
cout<<"enter number of elements in array";
cin>>n;
cout<<"enter the value of array elements"<<"\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n value of elements of array are";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
int max=a[0];
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
cout<<"largest number is"<<max;
getch();
}
0 comments:
Post a Comment