Problem Statement
Write a C program that reads a sequence of positive floating-point numbers from the
keyboard . It computes and finally prints the largest data in the data stream and
the contra harmonic mean of the data. The number of data is is not known a prior.
They are counted while reading. [You are not
allowed to use any array]
Write a C program that reads a sequence of positive floating-point numbers from the
keyboard . It computes and finally prints the largest data in the data stream and
the contra harmonic mean of the data. The number of data is is not known a prior.
They are counted while reading. [You are not
allowed to use any array]
#include<stdio.h>
int main()
{
float sum,sqsum ,contraharmonic, count,max,a;
sum=sqsum= count=max=0.0;
printf("enter the number sucessively and enter ctrl-d in the end \n");
while(scanf("%f",&a)!=EOF)
{
count=count+1;
sum=sum+a;
sqsum=sqsum+(a*a);
if(a>max)
{
max=a;
}
}
contraharmonic=(sqsum)/sum;
printf("the largest number u entered is %f \n",max);
printf("the contraharmonic mean is %f", contraharmonic);
return 0;
}
No comments:
Post a Comment