devC Write a C program that four integers The program should
(devC++)
Write a C program that four integers. The program should find max, min and average (with one decimal place format, i.e. 23.6) of these four inputs.Solution
#include <stdio.h>
void main()
{
int a[10];
int i, max, min, n,sum=0;
float average;
printf(\"Enter the size of the array: \");
scanf(\"%d\", &n);
printf(\"Enter elements in the array: \");
for(i=0; i<n; i++)
{
scanf(\"%d\", &a[i]);
}
max = a[0];
min = a[0];
for(i=0; i<n; i++)
{
if(a[i]>max)
{
max = a[i];
}
if(a[i]<min)
{
min = a[i];
}
sum=sum+a[i];
}
average=sum/n;
printf(\"Maximum element = %d\ \", max);
printf(\"Minimum element = %d\ \", min);
printf(\"average element = %.1f\", average);
}
Here if you want to give four inputs simply assign the value of n as 4 or you can also give any number of integers also.
