design and implement a program that reads floating-points
numbers in a sentinel-controlled loop until the user
terminates the program by entering zero.your program should
determinate and print the smallest,largest and average of
the supplied numbers.
Answer Posted / yogesh
#include<stdio.h>
#define MAX 20
int main()
{
float no,a[MAX],sum=0.0,avg;
int n,i;
float min,max;
printf("\n Enter How Many Numbers:");
scanf("%d",&n);
i=0;
min=0;
max=0;
do
{
printf("\n Enter a number(Enter 0 to
stop):");
scanf("%f",&no);
a[i]=no;
if(no==0)
break;
else
{
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
sum=sum+a[i];
}
i++;
}
while(i<n);
avg=sum/i;
printf("\n The Smallest Number is:%f",min);
printf("\n The Largest Number is:%f",max);
printf("\n The Average of Entered %d numbers is:%.2f
\n",i,avg);
}
Is This Answer Correct ? | 1 Yes | 3 No |
Post New Answer View All Answers
What are compound statements?
in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures
how logic is used
What is C language ?
Which function in C can be used to append a string to another string?
What is context in c?
What is the use of typedef in c?
What is function what are the types of function?
What is #define size in c?
In c language can we compile a program without main() function?
Explain what are bus errors, memory faults, and core dumps?
How can I pad a string to a known length?
What's a good way to check for "close enough" floating-point equality?
What is main return c?
Why should I use standard library functions instead of writing my own?