1 . What is the output of the following C++ loop? for ( int K =11 ; K >= 1 ; K =
ID: 3674250 • Letter: 1
Question
1 . What is the output of the following C++ loop? for ( int K =11 ; K >= 1 ; K = K + 2 ) cout << K << endl;
2. What is the output of the following loop? int M = 1; while ( M < = 20 ) { if ( M % 5 = = 0 ) continue; else cout << M<
3. What is the output of the following loop?
int X=2;
while ( X < =10 )
cout << X << endl;
X = X + 2;
4.What are the values of variables total and count after the following program segment is executed?
int count = 0 ;
int total = 5 ;
while ( count < 5 )
{
total = total + count ;
count = count + 1;
}
cout<<” total is “<< total<<endl;
cout<<” count is “<<count<<endl;
5.What is the value of variable counter after the following program segment executes?
int counter = 2 ;
while ( counter < 10 )
count = counter + 2 ;
cout << “ the counter is” <<counter << endl;
6. Write a complete C++ program that will display characters M-Z (uppercase) on your monitor.
Explanation / Answer
1. This code will print
11
13
15
17
19
...
odd numbers infinately
2. this code will print
1
2
3
4
6
7
8
9
11
...
infinately
3. this code will print
2
2
2
2
...
infinately
4.
count total
0 5
1 6
2 8
3 11
4 15
5.
the counter is 2
6.
#include<iostream.h>
void main()
{
cout<<"M";
cout<<"N";
cout<<"O";
cout<<"P";
cout<<"Q";
cout<<"R";
cout<<"S";
cout<<"T";
cout<<"U";
cout<<"V";
cout<<"W";
cout<<"X";
cout<<"Y";
cout<<"Z";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.