Find maximum in array by R4R Team

Array:

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

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

program-

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


output-

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

-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 maxumum and check other elements,if any other element is greator then max then assign number to max 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!