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.

Answers were Sorted based on User's Feedback



design and implement a program that reads floating-points numbers in a sentinel-controlled loop un..

Answer / sagarraje nimbalkar

// above student asking user How many no. ? but their is no
need to ask because when user want to stop he will enter o(zero)

#include<stdio.h>
#include<conio.h>

void main()
{
int i=1;
float max=0, min=0;
do
{
float n, sum=0, avg=0;
printf("Enter the %d th number: ",i);
scanf("%f",&n);
if(n==0)
exit(0);
else
{
sum=float(sum+n);
if(n>max)
max=n;
else
min=n;
}
i++;
while(1);
printf(" The maximum no. is %f and minimum no. is %f and
average of all no is %f",max,min,sum/i);
getch();
}

Is This Answer Correct ?    1 Yes 1 No

design and implement a program that reads floating-points numbers in a sentinel-controlled loop un..

Answer / 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

More C Interview Questions

What is variable in c example?

0 Answers  


Can you explain the four storage classes in C?

0 Answers   TCS,


the data type used for unlimited value in c and how to do this program

1 Answers  


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


what is foreign key in c language?

1 Answers   ADP,






What is the difference between class and object in c?

0 Answers  


write a function to find whether a string is palindrome or not and how many palindrome this string contain?

2 Answers   Aptech,


plz answer..... a program that reads non-negative integer and computes and prints its factorial

2 Answers  


What is function and its example?

0 Answers  


Tell me what is null pointer in c?

0 Answers  


Is a house a shell structure?

0 Answers  


p*=(++q)++*--p when p=q=1 while(q<=6)

0 Answers   KINPOE,


Categories