Assignment on Looping Constructs
Assignment on control structures
Q. 1 Identify
the following in the loops:
- I. Loop control variable
- II. Initialization expression
- III. Update expression
- IV. Test expression
a. a. for (int
p=4; p<9; p++)
cout<<p;
b. b. int x=9;
do
{
cout<<x++;
}while(x<15);
c. C. int m=6;
while(m<15)
{ cout<< m;
m++;
}
d.
d. char ch=’a’;
d. char ch=’a’;
while(ch<’g’)
{ cout<<ch;
ch++;
}
Q.2.
Fill up the blanks for the following loops:
a. A loop to
find and display the sum of numbers between 4 and 40.
int sum=________;
for(_________;________;___________)
sum___________;
__________________
b. A loop to find and display the sum of
multiples of 3 between 10 and 40.
int sum=________;
for(_________;________;___________)
sum=___________;
__________________
c. . A loop
to count the numbers between 4 and 40.
int count=________;
for(_________;________;___________)
count__________;
__________________
d. A loop to count the multiples of 3 between 15
and 45.
int count=________;
for(_________;________;___________)
count___________;
__________________
e.. A loop
to count the even numbers between 8 and
90.
int count=________;
int
x=_________
do
{ if(____________)
____________
___________
}while(____________);
f. A loop to find the sum of factors of a number
n;
int ___________, sum=________;
cin>>_________;
int x=__________;
while(___________)
{
if(___________)
__________________;
___________;
}
Comments
Post a Comment