g An athlete runs every day for five days. Write a program that computes the total distance and average distance ran by the athlete. The program should ask the user for the number of miles run on each day (Monday to Friday), and save the values entered by the user in five different variables. The program should first calculate the total miles ran by the athlete and store the result in a variable named sum. Then the program should compute the average distance covered and store it in a variable named average. Display the total distance and the average distance on the screen. Name your program file Hw1_q1_code.c. (TIP: Use scanf function, and float/double data type for all variables)

Respuesta :

Answer:

// here is program in C.

#include <stdio.h>

// main function

int main(void) {

// variables

   float d_mon,d_tue,d_wed,d_thu,d_fri;

printf("enter distance ran on monday:");

 // read distance on monday

scanf("%f",&d_mon);

printf("enter distance ran on tuesday:");

 // read distance on tuesday

scanf("%f",&d_tue);

printf("enter distance ran on wednesday:");

 // read distance on wednesday

scanf("%f",&d_wed);

printf("enter distance ran on thursday:");

 // read distance on thursday

scanf("%f",&d_thu);

printf("enter distance ran on friday:");

 // read distance on friday

scanf("%f",&d_fri);

 // total distance

float sum=d_mon+d_tue+d_wed+d_thu+d_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 on monday:12

enter distance ran on tuesday:10

enter distance ran on wednesday:5

enter distance ran on thursday:13

enter distance ran on friday:12

total distance ran by athlete is: 52.000000 miles

average distance ran each day is: 10.400000 miles