Write a Program to Find a Smallest Number in a Array.

Working

  • Make an Array.
  • Set First Element as Min Number.(10000000)
  • Compare Each Element with Min Number
  • If New Number is Lower Then Min Number Then New Number Assign as Min Number.
  • In End Min Number.
  • Min Number is Minimum/Smallest Number in a Array.

Program

//Find a Smallest Number in a Array
#include<iostream.h>
#include<conio.h>
int min_number(int arry[],int len){
int min_num = 1000000;
for(int i=0;i<len;i++){
if(arry[i]<min_num){
min_num=arry[i];
}
}
return min_num;
}
void main(){
clrscr();
int min,len=0;
int array[50];
cout<<"\n Find a Smallest Number in a Array ";
cout<<"\n -------------------------------- ";
cout<<"\n Enter a Length of Array ";
cin>>len;
cout<<" Enter the "<<len<<" Numbers \n";
for(int i=0;i<len;i++){
cout<<" Value "<<i+1<<" : ";
cin>>array[i];
}
min = min_number(array,len);
cout<<"\n The Smallest Number in Array is "<<min;
getch();
}

Output / Result

Find a Smallest Number in a Array.
Find a Smallest Number in a Array.

 

(Visited 148 times, 1 visits today)
Share with Friends :