Answer:
// here is Hw1_q1_code.c
#include <stdio.h>
// main function
int main(void) {
// variables
float dis_mon,dis_tue,dis_wed,dis_thu,dis_fri;
printf("enter distance ran by athlete on monday:");
// read distance on monday
scanf("%f",&dis_mon);
printf("enter distance ran by athlete on tuesday:");
// read distance on tuesday
scanf("%f",&dis_tue);
printf("enter distance ran by athlete on wednesday:");
// read distance on wednesday
scanf("%f",&dis_wed);
printf("enter distance ran by athlete on thursday:");
// read distance on thursday
scanf("%f",&dis_thu);
printf("enter distance ran by athlete on friday:");
// read distance on friday
scanf("%f",&dis_fri);
// total distance
float sum=dis_mon+dis_tue+dis_wed+dis_thu+dis_fri;
// average distance
float average=sum/5;
// print the total and average
printf("total distance ran by athlete is: %f miles",sum);
printf("\naverage distance ran each day is: %f miles",average);
return 0;
}
Explanation:
Declare five variables to store distance ran by athlete on each day from monday to friday.Read the five distance.Then calculate their sum and assign to variable "sum".Find the average distance ran by athlete by dividing sum with 5 and assign to variable "average".Then print the total distance ran and average distance on each day.
Output:
enter distance ran by athlete on monday:10
enter distance ran by athlete on tuesday:11
enter distance ran by athlete on wednesday:8
enter distance ran by athlete on thursday:9
enter distance ran by athlete on friday:12
total distance ran by athlete is: 50.000000 miles
average distance ran each day is: 10.000000 miles