Find minimum in array Data structure by R4R Team

Array:

collection of same data type.
-We have to find the minimum in integer array.

Example-
array is {1,2,3,6,0,34,21}
then minimum is 0

program-

#include < stdio.h>
int main()
{
int a[20],i,min;
printf("Enter 10 number in array\n");
for(i=0;i< 10;i++)
scanf("%d",&a[i]);
min=a[0];
for(i=1;i< 10;i++)
{
if(a[i]< min)
min=a[i];
}
printf("Minimum number in array is %d",min);
}


output-

Enter 10 number in array
1 2 3 4 5 6 7 8 9 0
Minimum number in array is 0

-In this program, we create a array with max size 20, but we take an input of 10 numbers in array.
-Then we take first number as a minimum and check other elements,if any other element is smallest then min then assign number to min and continue this process until loop finish.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!