Professional Documents
Culture Documents
LOOPING
STATEMENTS
LOOPING STATEMENT
one of the most frequently used looping statement is the for loop
statement. The reason why behind that is the for loop statement is very
easy to use and implement because all the declaration for the initializing
value, conditions and increment/decrement is written in a single line of
code.
Syntax
for (initialization; conditional expression; increment/decrement expression)
{
statement1;
statement2;
statement3;
}
Initialization – This is an assignment statement that is
used to set a loop control value
cout<<"\n\n";
cout<<"\tEnd of the Program";
cout<<"\n\n";
}
Problem No. 1
Design a program that will ask the user to give a number and then the program
will display the list of ODD and EVEN numbers using for loop statements.
Problem No. 2
Write a program that will ask the user to give a number and then the program
will calculate the total sum of the numbers using for looping statement.
Problem No. 3
Design a program that will ask the user to give a number and then the program
will determine and check if the given number is a Prime number or NOT a Prime
Number using for loop statement.
WHILE LOOP STATEMENT
}
Problem No. 1
Design a program that will ask the user to give number and then the program
will compute the sum of all the digits of the given number using while loop statement.
Problem No. 2
Write a program that will accept a number from the user and then the program
will reverse the arrangement of the given number by the user using while loop statement.
DO WHILE LOOP STATEMENT
do{
cout<<" "<<a<<" ";
a++;
}while (a<=num);
cout<<"\n\n";
cout<<"\t End of the Program";
}
Problem No. 1
Desing a program that will as the user to give two numbers and then the
program will compute the sum of the two numbers and display the result on the screen.
After which the program will ask the user if the user would like to continue using the
program or not using do while statement.
Problem No. 2
Design a program that will ask the user of two numbers and then the program
will compute the LCM of the two numbers using do while loop statement.