Tuesday, January 17, 2012

Find Maximum Value in Array


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],max,i;
clrscr();
printf(“enter elements for the array\n”);
for(i=0;i<5;i++)
scanf(%d”,&a[i]);
max=a[0];
for(i=1;i<5;i++)
{
if(max<a[i])
max=a[i];
}
printf(“the maximum value is%d”,max);
getch();
}

Output:
enter the elements for array
4
6
3
8
5
the maximum value is 8 

No comments:

Post a Comment