Smallest of given 'n' numbers & its location:
AIM:
To find the smallest of given 'n' numbers & its location.
THEORY:
The
smallest number in list of numbers is a number which has the smallest value as
compared to the other values in that list.
The
smallest of ‘n’ numbers & its location /position can be found by C++ using the following codes.
CODING:
#include<iostream.h>
#include<conio.h>
void main()
{
int a[25],n,i,p=0,m;
clrscr();
cout<<"Enter a number:";
cin>>n;
cout<<"Enter "
""<<n<<"numbers:"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
m=a[0];
for(i=0;i<n;i++)
{
if (m>a[i])
{
m=a[i];
p=i;
}
}
cout<<"Smallest number
is:"<<m<<endl;
cout<<"The position of smallest no. is:"<<p+1<<endl;
getch();
}
OUTPUT:
Model syllabus (+3): Downoad
- How to Prepare for IIT-JAM ⇠ ⇠ Click Here
- How to prepare for JEST ⇠ ⇠ Click Here
Post a Comment