Lab#10
Lab#10
The for statement provides a mechanism to repetitively perform operations. The general format of
the for statement is:
#include <iostream>
using namespace std;
int main()
{
int counter1;
for( counter1 = 1; counter1 <5; counter1++)
{
cout<<" The square value of " <<counter1<<":\t\t"<<counter1*counter1<<endl;
cout<<"\n"<<endl;
}
return 0;
}
- Modify the program to compute the square for all integer numbers that are greater than 0
and smaller than 10.
- Modify the program to compute the square for the even integer numbers that are greater
than 0 and smaller than 10.
- Modify the program to compute the square for the odd integer numbers that are greater
than 0 and smaller than 10.
The while statement is used to execute a block of statements while some condition is true. In this
exercise, you will use the while statement to repetitively read inputs from the terminal.
The C program below defines two integer variables number1 and number2. The while statement is
used to continuously read the values of number1 and number2 from the terminal, and then compute
their sum.
Page 1 of 2
Computing Fundamentals CS1150 ______ Lab NO. 10: C++ programming
#include <iostream>
int main()
{
return 0;
}
1. How many times does the program above read the values of number1 and number2 and then
compute their sum?
_________________________________________
2. Modify the above program to run the while loop for 10 interactions.
3. Modify the above program to compute subtraction, multiplication and division.
4. Modify the above program to run the while loop for infinite number of iterations (endless
loop).
Page 2 of 2