Question: Question 5 ( 2 0 marks ) A program written to calculate the mean of three input data from the user which is listed as

Question 5(20 marks)
A program written to calculate the mean of three input data from the user which is listed as below:
```
#include
void main(void)
{ float value0, value1, value2, total =0, mean;
printf ("This program takes in three data ");
printf ("and calculate the mean.
"); //Introduction
printf ("Enter data no.1 : "); //Prompt user
scanf ("*/f", &value0); //Get the first data
total = total + value0; //Obtain the total
printf ("Enter data no.2 : "); //Prompt user
scanf ("%f", &value1); //Get the second data
total = total + valuel; //Obtain the total
printf ("Enter data no.3 : "); //Prompt user
scanf ("%f", &value2); //Get the third data
total = total + value2; //Obtain the total
mean = total /3.0; //Calculate the mean
printf ("The mean is %f
", mean);
}//End of program
```
Program 3
Analyze Program 3 in detail and answer the following questions:
(a)(i) State the data type used by all the variables in Program 3.
[2 marks]
(ii) Explain two drawbacks of the method used in Program 3 to collect data.
(iii) Explain the purpose of initializing the variable total.
(b) Modify Program 3 to take in any number of input data and calculate the mean from the input data.
- Use array to store the input data.
- The number of input data is determined by the user, with maximum up to 1000 data.
- Use the preprocessor directive: \#define to set the maximum number of input data at 1000.
- The program needs to check whether the number of input data keyed in by the user exceeds the maximum allowable size or not, which is 1000. Write a function for this purpose, which can be called from the main function.
- Use loop to repeatedly collect the input data from the user and store them in the array.
Question 5 ( 2 0 marks ) A program written to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!