Tuesday, December 18, 2012

FIND THE LARGEST AND SMALEST ELEMENT IN A VECTOR IN C++


 #include<iostream.h>
void main()
{
int count, num, vec[100], large, small;
cout<<"ENTER HOW MANY ELEMENTS ARE THERE IN THE VECTOR : ";
cin>>num;
cout<<"\nENTER THE VALUES IN THE VECOR \n";
for(count=0; count<num; count++)
cin>>vec[count];
large=small=vec[1];
for(count=0; count<num;count++)
{
if(vec[count]>large)
large=vec[count];
else if(vec[count]<small)
small=vec[count];
}
cout<<"\nTHE LARGEST ELEMENT IS : "<<large<<endl;
cout<<"\nTHE SMALLEST ELEMENT IS : "<<small<<endl;
}


No comments: