Your Ad Here

Thursday, February 26, 2009

Write a C++ program to find both the largest and smallest number in a list of integers.

#include(iostream.h) // place this '<' & '>' instead of '(' & ')' before iostream.h
#include(conio.h)
void main(void)
{
int a[50], max, min, i, n;
clrscr( );
cout<<"Enter how many integers do u want? :"; cin>>n;
for( i=0; i< n ; i++)
{
cout<<"Enter the numbers: ";
cin>>a[ i ];
if(i==o) { max=a[i ]; min=a[i ]; }
if(a[ i]>max)
max= a[i ];
if(a[i ]< min)
min= a[i ];
}
cout<<"Maximum : "<< max;
cout<<"Minimum : "<< min;
getch( );
}

Note:- If u have any doubt regarding this program or logic, please feel free to contact me.

8 comments: