Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
33 views4 pages

Quiz 3 Fall 2014 Solution

The document is a quiz for an Introduction to Computing and Programming course, consisting of 15 questions that require students to determine the output of various C/C++ code snippets. Each question presents a different coding scenario, testing the student's understanding of loops, conditionals, and data types. The quiz is designed to be completed in 25 minutes.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Quiz 3 Fall 2014 Solution

The document is a quiz for an Introduction to Computing and Programming course, consisting of 15 questions that require students to determine the output of various C/C++ code snippets. Each question presents a different coding scenario, testing the student's understanding of loops, conditionals, and data types. The quiz is designed to be completed in 25 minutes.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Quiz # 3

Introduction to Computing and Programming

Name: _______________________ Reg. no. ___________________


Section: _______

Note: Attempt all question. Max. Time: 25 minutes

For the following problems, assume that preprocessor directives/header files have already
been included at the start of the program, and code given in each problem is part of the
main() function.

1- What is the output of the following C/C++ code?

for(int i = 0 ; i < 10 ; ++i )


cout<<" "<<i;
}
0123456789

2- What is the output of the following C/C++ code?

for(int i = 48 ; i > 0 ; i -= 4 )
cout<<" "<<50 - i;
2 6 10 14 18 22 26 30 34 38 42 46

3- What is the output of the following C/C++ code?

for(int i = 50 ; i > 0 ; i -= 5 ){
cout<<" "<<i;
i++;
}
50 46 42 38 34 30 26 22 18 14 10 6 2

4- What is the output of the following C/C++ code?

int count, product = 1;


for ( count = 1; count < 6; count++ )
{
if ( count == 4 )
break;
product *= count;
cout <<"("<<count << " , " << product << " , " <<product % 10 << "); ";
} // end for

( 1 , 1 , 1 ); ( 2 , 2 , 2 ); ( 3 , 6 , 6 );

1
5- What is the output of the following C/C++ code?

for ( int i = 0, j = 11; ( j + i <= 22 ) && ( j > -10 ) ; j -= 2, i++)


cout << j + i << " ";

11 10 9 8 7 6 5 4 3 2 1

6- What is the output of the following C/C++ code?

double y, total= 0;
int x = 1;
while ( total <= 50 ) {
y = pow(2 ,x) ;
cout << y << " ";
total += y;
x++;
}
2 4 8 16 32

7- Suppose that the following C/C++ code is executed and the user enters ‘F’ on the prompt.
What will be printed on the screen (including what the user entered)?

char grade = 'A';


do {
if (grade == 'F')
cout<<"You failed. Take the course again!\n";
else
cout<<"Excellent Grade!\n";
cin>>grade;
}
while (grade == 'A');

Excellent Grade!
F

8- What is the output of the following C/C++ code?


int count = 10;
do {
count--;
}
while(count > 0);
cout<<count;
0

9- What is the output of the following C/C++ code?


int count = 11;

2
while ( count != 0 ) {
cout<< count<<" ";
count = count - 2;
}
Semantics/logical error- (Infinite loop)

10- What is the output of the following C/C++ code?

int number = 1, sum=0;


while ( (number <=5) || (sum < 12) ) {
cout<< sum<<" ";
number++;
sum += number;
}

0 2 5 9 14

11- What is the output of the following C/C++ code?

cout<<"\n\nQ11:\n";
int number = 1, Total=10;
while ( (number <=5) && (Total > 0) ) {
cout<< Total<<" ";
number++;
Total -= number;
}

10 8 5 1

12- What is the output of the following C/C++ code?

cout<<"\n\nQ12:\n";
int x=1, product=1;
while ( x <= 10 ) {
product = product * 2;
++x;
}
cout<< product<<" ";

1024

13- What is the output of the following C/C++ code?

int i=0;
for(i=1 ;i<=10; i++);
cout<< i;

3
11

14- What is the output of the following C/C++ code?

int a = 10,b = 4;
float f;
f = a / float(b);
cout<< f;

2.5

15- What is the output of the following C/C++ code?

int a = 10,b = 4;
int f;
f = a / float(b);
cout<< f;

You might also like