Hey guys could someone help me with this question using #include<stdio.h>
First produce a program which requests the inputs of ten floating point numbers between zero and one hundred and stores these numbers in an array. The program should then print the array, calculate the minimum and maximum numbers entered and their average.
Second Create a copy of the above program and modify it such that up to a set maximum number of floating point numbers can be entered. You should make use of a constant with a suitable name (e.g. MAX_SIZE) and use a sentinel value such as -1 to mark the end of input.
code for the first part:
#include <stdio.h>
#include <conio.h>
float maximum(float a[]);
float minimum(float a[]);
float average(float a[]);
int main()
{
float a[10];
int j,k;
float b,max,min,aver;
printf("Enter 10 floating numbers between 0 and 100\n");
for (j=0;j<10;j++)
{
x:
printf("Enter the %d element\n ",j+1);
scanf("%f",&b);
if (b>0.0 && b<100.0)
{
a[j] = b;
}
else
{
printf("Entered number not in range\n");
printf("Re enter the number\n");
goto x;
}
}
printf("Entered numbers are\n");
for (k=0;k<10;k++)
{
printf("%f\n",a[k]);
}
max = maximum(a);
min = minimum(a);
aver = average(a);
printf("The maximum number entered is : ");
printf("%f\n",max);
printf("The minimum number entered is : ");
printf("%f\n",min);
printf("The average of enterd number is :");
printf("%f\n",aver);
return 0;
}
float maximum(float a[10])
{
int m;
float c;
c = a[0];
for(m=1;m<10;m++)
{
if (a[m]>c)
{
c = a[m];
}
}
return c;
}
float minimum(float a[10])
{
int n;
float d;
d = a[0];
for(n=1;n<10;n++)
{
if (a[n]<d)
{
d = a[n];
}
}
return d;
}
float average(float a[10])
{
float sum = 0,avg;
int z;
for (z=0;z<10;z++)
{
sum = sum + a[z];
}
avg = sum/10;
return avg;
/*Code Written by geek007*/
}