Structured program with a repetition counter

Instructions:
* Use the steps to create a template program such as the simple program I ("Hello World!) Ago, but use a different Project_name, for example Program5

* Replace the main functions of the program block (remember, that meant the block is the line of command between the {and} from the main function), with the following:


int counter; /* number of grade to be entered next */
int grade; /* grade value */
int total; /* sum of grades input by user */
int average; /* average of grades */


/* initialization phase */
total = 0; /* initialize total */
counter = 1; /* initialize loop counter */

/* processing phase */
while ( counter <= 10 ) { /* loop 10 times */ printf( "Enter grade: " ); /* prompt for input */ scanf( "%d", &grade ); /* read grade from user */ total = total + grade; /* add grade to total */ counter = counter + 1; /* increment counter */ } /* end while */ /* termination phase */ average = total / 10; /* integer division */ printf( "Class average is %d\n", average ); /* display result */ return 0; /* indicate program ended successfully */Output Program:Enter grade: 98Enter grade: 76Enter grade: 71Enter grade: 87Enter grade: 83Enter grade: 90Enter grade: 57Enter grade: 79Enter grade: 82Enter grade: 94Class average is 81 copy right by
Berbagi Tips dan Trik

Description: Structured program with a repetition counter
Rating: 4.5
Reviewed by: CasN
On: 10:12 pm
TOP