08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ Programs with Repetition Logic

13 is entered and stored in num;

num is not 0 so we enter the while loop;

num (13) is added to sum (24), giving:

num 13 sum 37

55 is entered and stored in num;

num is not 0 so we enter the while loop;

num (55) is added to sum (37), giving:

num 55 sum 92

32 is entered and stored in num;

num is not 0 so we enter the while loop;

num (32) is added to sum (92), giving:

num 32 sum 124

19 is entered and stored in num;

num is not 0 so we enter the while loop;

num (19) is added to sum (124), giving:

num 19 sum 143

0 is entered and stored in num;

num is 0 so we exit the while loop and go to print sum with

num 0 sum 143

sum is now 143 so the algorithm prints 143.

When a while construct is being executed, we say the program is looping or the while loop is

being executed.

It remains to show how to express this algorithm in C. Program P5.1 shows how.

94

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!