Catatan Si DjaiL

Program berstruktur pengulangan dengan counter

Posted by: zonder77

Petunjuk:
* Gunakan langkah-langkah pembuatan template program seperti pada program sederhana I (“Hello World!) yang lalu , tetapi gunakan Project_name yang berbeda,misalnya Program5

* Gantilah blok program fungsi main ( ingat,yang dimaksud blok adalah barisan perintah diantara { dan } dari fungsi main),dengan yang berikut:

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

This entry was posted on 10:12 PM . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

0 komentar

Post a Comment

>

ShoutMix chat widget

Guestbook Rolling Widget