Assignment 5_C++ 1_Solution
Assignment 5_C++ 1_Solution
Semester 1 (2024-2025)
1. (What Does this Program Do?) What does the following program print?
This Program prints the squares of the integer numbers from 1 to 10 and the sum of those
squares
1
2. (What Does this Program Do?) What does the following program print?
3. Write a program that displays the following checkerboard pattern. Your program
must use only three output statements, one of each of the following forms:
2
4. Identify and correct the errors in each of the following:
a) while ( c <= 5 )
while ( c <= 5 )
(
{
product *= c;
product *= c;
++c;
++c;
)
}
must use { } instead of ( ) for while loop
c) if ( i == 1 )
cout << "A" << endl; if ( i == 1 ){
cout << "B" << endl; cout << "A" << endl;
else cout << "B" << endl;
cout << "C" << endl; }
else
missing { } for if statement cout << "C" << endl;
3
5. What’s wrong with the following while repetition statement?
while ( i <= 10 )
product *= i;
The value of the variable i is never changed in the while statement. Therefore, if the loop-continuation condition (i
<= 10) is initially true, an infinite loop is created