Write a program in C that calculate and print the summation of odd numbers between 1-15 and then find the average of the summation of these numbers, please use double data type to declare all variables. Use for or do/while loop, please explain the steps aswell
code:
#include <stdio.h>
int main()
{
//declaring the vairables
double i, sum=0,avg=0,count=0;
/* Find the sum of all odd number between 1-15*/
for(i=1; i<=15; i+=2)
{
count+=1;
sum += i;
}
//printing sum
printf("Sum of odd numbers = %f\n", sum);
//calculating average
avg=sum/count;
//printing Average
printf("Average of odd numbers = %f", avg);
return 0;
}
code:
output:
Get Answers For Free
Most questions answered within 1 hours.