Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write this program and explain what each line of code is doing in the pro

ID: 3548794 • Letter: P

Question

Please write this program and explain what each line of code is doing in the program. this needs to be in basic C programming


Write a program that prompts the user for an integer number from the keyboard, and store it in a variable num. After each number is typed in, add num to a total.


Do this six times, each time adding num to a total. (Be sure to reuse the same variable named num for each of the six numbers entered.) When all six numbers have been entered from the keyboard, calculate an average.


Display the total and average calculated.

Explanation / Answer

main()

{

int num, total ,i ;

float avg ; // The average of 6 no.'s may not be an integer so we take avg to be a float data-type

total = 0 ; // The total of the numbers is initialised to 0 as total is 0 when no no.'s are added

for( i=1 ; i<=6 ; i++ ) // the loop is executed from i=1 to i=1 which is 6 times which is what we need to scan 6 no.'s

{

printf(" Enter %d - number : " , i); // prompts the user to enter the number

scanf( "%d" , &num ); // stores the no. entered by the user in the variable

total = total + num ;

/* Adds the new number to the total... In C,statements are executed from left to right, so first left side of '=' is calculated which is total + num and this gives the new value for total and is again assigned to total on the right side of '=' */

}

avg = total / 6 ; // average of six numbers is total divided by 6

printf( " The total of 6 numbers is %d and their average is %f " , total , avg );

}