











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












In the last lecture
Loop - Repetition structure
while
int sum ; sum = 0 ;
int sum = 0; ( Optional )
int sum, number , UpperLimit ; sum = 0 ; number = 1 ; cout << “ Please enter the upper limit for which you want the sum ” ; cin >> UpperLimi t; while (number <= UpperLimit) { sum = sum + number ; number = number +1 ; } cout << “ The sum of the first ” << UpperLimit << “ integer is ” << sum ; Example
sum = 0; number = 1; cout << “ Please enter the upper limit for which you want the sum ”; cin >> UpperLimit; while (number <= UpperLimit) { if (number % 2 == 0) { sum = sum + number; number = number + 1; } } cout << “ The sum of all even integer between 1 and ” << UpperLimit << “ is” << sum; Example
Condition is While true? WHILE Statement Entry point for WHILE block Exit point for WHILE block Process Exit No
Factorial Definition
It executes zero or more times