write C program using function to read 20 float numbers and print the average of them after changing the negative to positive number.
Code:
#include <stdio.h>
void print_average() //defining print_average()
{
int i=1;
float num=0.0f,sum=0.0f;
for(i=1;i<=20;i++) //Looping 20 times
{
//Inputting number
printf("Enter Number %d: ",i);
scanf("%f",&num);
//summing the numbers after making negative ones positive
sum=sum+((num<0)?-num:num);
}
//Printing average
printf("The average of numbers: %f",(sum/20.0));
}
int main()
{
print_average(); //calling print_average() function
return 0;
}
Sample Output:
Get Answers For Free
Most questions answered within 1 hours.