/* The following C / C++ Program will find the smallest number among
numbers in the integer array thus entered by the user. We have used
while loop to read & write the array*/
Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int min,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
min=a[b]; //assuming that the 1st element is the minimum
while (b<n)
{
if (a[b]<=min) //if anything else is found to be more larger than the current minimum
{
min=a[b];
}
b=b+1;
}
cout<<"\nSmallest number is : "<<min;
getche();
}
Output:
Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int min,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
min=a[b]; //assuming that the 1st element is the minimum
while (b<n)
{
if (a[b]<=min) //if anything else is found to be more larger than the current minimum
{
min=a[b];
}
b=b+1;
}
cout<<"\nSmallest number is : "<<min;
getche();
}
Output:
C / C++ Program to find the Smallest number from the array of integers |
0 comments:
Post a Comment