C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).
C Program to determine the Range and Average of the values entered by the user(to terminate enter -1).
This is a program to calculate the range and average of the values entered by the user and to terminate it by entering -1 and it will determine the highest-value, lowest-value, range, average and also it will count the number of values entered by the user.
PROGRAM:
#include<stdio.h>
#include<math.h>
int main()
{
int count=0;
float value,high,low,average,range,sum=0;
printf("Enter the values (to terminate enter -1) :\n");
while(1)
{
scanf("%f",&value);
if(value!=-1)
{
count++;
sum=sum+value;
if(count==1)
{
low=high=value;
}
else if(value>high)
{
high=value;
}
else if(value<low)
{
low=value;
}
}
else
{
break;
}
}
average=sum/count;
range=high-low;
printf("Total values : %d",count);
printf("Highest-value : %f",high);
printf("Lowest Value : %f",low);
printf("Range : %f",range);
printf("Avergae : %f",average);
return 0;
}
OUTPUT:
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link