C Exam
C Exam
int main() {
cout
<< "Hello World!";
return 0;
}
int main() {
\n
cout << "Hello World! ";
cout << "I am learning C++";
return 0;
}
3. Comments in C++ are written with special characters. Insert the missing parts:
//
This is a single-line comment
/* */
This is a multi-line comment
int myNum 50
= ;
int x 5
= ;
int y = 10;
cout << x + y;
int x = 5;
int y = 10;
int z
= x + y;
z
cout << ;
7. Fill in the missing parts to create three variables of the same type, using a comma-
separated list:
int , ,
x = 5 y = 6 z = 50;
cout << x + y + z;
8. Use the correct keyword to get user input, stored in the variable x:
int x;
cout << "Type a number: ";
cin x
>> ;
9. Fill in the missing parts to print the sum of two numbers (which is put in by the user):
int x, y;
int sum;
cout << "Type a number: ";
cin x
>> ;
cout << "Type another number: ";
cin y
>> ;
sum = x + y;
sum
cout << "Sum is: " << ;
*
cout << 10 5;
11. Use the correct operator to increase the value of the variable x by 1.
int x = 10;
++
x;
12. Use the addition assignment operator to add the value 5 to the variable x.
int x = 10;
+=
x 5;
13. Use the correct operator to concatenate two strings:
14. Use the correct function to round the number 2.6 to its nearest integer.
#include <iostream>
cmath
#include < >
using namespace std;
int main() {
round
cout << (2.6);
return 0;
}
15. Fill in the missing parts to print the value true (for true):
int x = 10;
int y = 9;
x > y
cout << ( );
int x = 50;
int y = 10;
if >
(x y) {
cout << "Hello World";
}
17. Print "Hello World" if x is equal to y.
int x = 50;
int y = 50;
if ==
(x y) {
cout << "Hello World";
}
int x = 50;
int y = 50;
if ==
(x y) {
cout << "Yes";
else
} {
cout << "No";
}
19. Print "1" if x is equal to y, print "2" if x is greater than y, otherwise print "3".
int x = 50;
int y = 50;
if ==
(x y) {
cout << "1";
else if >
} (x y) {
cout << "2";
else
} {
cout << "3";
}
int i = 1;
w hile
(i < 6) {
cout << i << "\n";
i++
;
}
1) Insert the missing part of the code below to output "Hello World!".
int main() {
<< "Hello World!";
return 0;
}
int main() {
cout << "Hello World! ";
cout << "I am learning C++";
return 0;
}
3) Comments in C++ are written with special characters. Insert the missing parts:
= ;
= ;
int y = 10;
cout << x + y;
int x = 5;
int y = 10;
= x + y;
cout << ;
7) Fill in the missing parts to create three variables of the same type, using
a comma-separated list:
x = 5 y = 6 z = 50;
cout << x + y + z;
8) Use the correct keyword to get user input, stored in the variable x:
int x;
cout << "Type a number: ";
>> ;
9) Fill in the missing parts to print the sum of two numbers (which is put in by the
user):
int x, y;
int sum;
cout << "Type a number: ";
>> ;
cout << "Type another number: ";
>> ;
sum = x + y;
cout << "Sum is: " << ;
cout << 10 5;
11) Use the correct operator to increase the value of the variable x by 1.
int x = 10;
x;
12) Use the addition assignment operator to add the value 5 to the variable x.
int x = 10;
x 5;
13) Use the correct operator to concatenate two strings:
14) Use the correct function to round the number 2.6 to its nearest integer.
#include <iostream>
#include < >
using namespace std;
int main() {
cout << (2.6);
return 0;
}
15) Fill in the missing parts to print the value true (for true):
int x = 10;
int y = 9;
cout << ( );
int x = 50;
int y = 10;
(x y) {
cout << "Hello World";
}
17) Print "Hello World" if x is equal to y.
int x = 50;
int y = 50;
(x y) {
cout << "Hello World";
}
int x = 50;
int y = 50;
(x y) {
cout << "Yes";
} {
cout << "No";
}
19) Print "1" if x is equal to y, print "2" if x is greater than y, otherwise print "3".
int x = 50;
int y = 50;
(x y) {
cout << "1";
} (x y) {
cout << "2";
} {
cout << "3";
}
int i = 1;
(i < 6) {
cout << i << "\n";
;
}