Here we will write a program to find the maximum and minimum elements of an integer array.
#include<stdio.h>
int main()
{
int a[10], i,max,min; // Here we are taking ten elements
printf("Enter the elements:\n") ;
for(i=0; i<=9; i++)
{
scanf("%d", &a[i]);
}
max=a[0];
min=a[0];
for(i=0;i<=9;i++)
{
if(a[i]>=max)
max=a[i];
if(a[i]<=min)
min=a[i];
}
printf("Max value = %d",max);
printf("\nMin value = %d",min);
return 0;
}
No comments:
Post a Comment