Answer:
Complete code with step by step comments for explanation and output results are provided below.
Code with Explanation Part-1:
#include <stdio.h>
int main()
{
// an array of four integers of type int is defined to store the data from the user
int number[4];
// variables of type int to store the result of product and average of numbers
int prod, avg;
printf("Please enter the four integers: ");
// get four integers from the user, %d specifier is used for int
scanf("%d %d %d %d",&number[0],&number[1], &number[2],&number[3] );
// calculate the product of numbers by multiplying them together
prod= number[0]*number[1]*number[2]*number[3];
// calculate the average of numbers by dividing the sum of numbers with total numbers
avg= (number[0]+number[1]+number[2]+number[3])/4;
// print the product and average of the numbers
printf("The product of the four numbers is = %d\n",prod);
printf("The Average of the four numbers is = %d",avg);
return 0;
}
Output Part-1:
Please enter the four integers: 8 10 5 4
The product of the four numbers is = 1600
The Average of the four numbers is = 6
As you can see, by using int type we are not getting the exact value of average.
Code with Explanation Part-2:
#include <stdio.h>
int main()
{
// here we just changed the type from int to float
float number[4];
float prod, avg;
printf("Please enter the four integers: ");
// %f specifier is used for floating point numbers
scanf("%f %f %f %f",&number[0],&number[1], &number[2],&number[3] );
prod= number[0]*number[1]*number[2]*number[3];
avg= (number[0]+number[1]+number[2]+number[3])/4;
// %0.3f is used to show up to 3 decimal digits
printf("The product of the four numbers is = %0.3f\n",prod);
printf("The Average of the four numbers is = %0.3f",avg);
return 0;
}
Output Part-2:
Please enter the four integers: 8 10 5 4
The product of the four numbers is = 1600.000
The Average of the four numbers is = 6.750
As you can see, by using float type we are getting the exact value of average.