FIND SMALLEST & LARGEST IN ARRAY
C++ code :)
#include<iostream>
using namespace std;
int main()
{
double a[100];
int min,n,i,loc=1;
cout<<"Enter size of arrray of:";
cin>>n;
cout<<"Enter "<<n<<" integers:"<<endl;
for(i=0; i<n; i++)
{
cin>>a[i];
}
min=a[0];
for(i=0;i<n;i++)
{
if(min>=a[i])
{
min=a[i];
loc=i+1;
}
}
if(loc == 1)
{
cout<<"Minimum number is found at 1st place";
cout<<endl<<"And that number is:" <<min<<endl;
}
else if(loc == 2)
{
cout<<"Minimum number is found at 2nd place";
cout<<endl<<"And that number is:" <<min<<endl;
}
else if(loc == 3)
{
cout<<"Minimum number is found at 3rd place";
cout<<endl<<"And that number is:" <<min<<endl;
}
else
{
cout<<" Minimum number is found at "<<loc<<"th place";
cout<<endl<<" And that number is:" <<min<<endl;
}
return 0;
}
0 Comments