thumbnail

What Does This C++ Code Do? - Click Quiz

You are given 12 different pieces of C++ code. Try to match each one with what it does.
Try the whole series here
Save time by using Keyboard Shortcuts
Quiz by akjlddkjslfsd
Rate:
Last updated: December 1, 2023
You have not attempted this quiz yet.
First submittedDecember 1, 2023
Times taken7
Average score66.7%
Report this quizReport
4:00
0
 guessed
12 remaining
The quiz is paused. You have remaining.
Scoring
You scored / = %
This beats or equals % of test takers also scored 100%
The average score is
Your high score is
Your fastest time is
Keep scrolling down for answers and more stats ...
int a, b;
cin >> a >> b;
cout << (a < b ? a : b) << endl;
string a;
getline(cin, a);
for(int i = a.length() - 1; i >= 0; i--) cout << a[i];
cout << endl;
int a, b;
cin >> a >> b;
cout << a + b << endl;
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) { if(a[i] % 2 == 1) r += a[i]; }
cout << r << endl;
string a;
getline(cin, a);
for(int i = 0; i < a.length(); i++) { if(i % 2 == 0) cout << a[i]; }
cout << endl;
int a, b;
cin >> a >> b;
cout << (a > b ? a : b) << endl;
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) r += a[i];
cout << r << endl;
int a = 1, b = 1;
cout << a << ' ' << b << ' ';
for(int i = 3; i <= 10; i++) { int t = a; a = b; b = t; a = a + b; cout << a << ' '; }
cout << endl;
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) { if(a[i] % 2 == 0) r += a[i]; }
cout << r << endl;
int a, b;
cin >> a >> b;
cout << a * b << endl;
string a, b;
getline(cin, a);
for(int i = 0; i < a.length(); i++) { if(a[i] >= 'A' && a[i] <= 'Z') b += a[i]; }
cout << b << endl;
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) r += a[i];
r /= sizeof(a) / sizeof(a[0]);
cout << r << endl;
Prints the average of an array of integers
Prints the first 10 numbers in the Fibonacci sequence
Prints the sum of all even numbers in an array of integers
Prints the sum of all odd numbers in an array of integers
Prints the sum of an array of integers
Reads a string from stdin and prints every other character
Reads a string from stdin and prints it out in reverse
Reads a string from stdin, discards all chars that aren't uppercase letters, then prints the new string
Reads two integers from stdin and prints the maximum of those integers
Reads two integers from stdin and prints the minimum of those integers
Reads two integers from stdin and prints their product
Reads two integers from stdin and prints their sum
Comments
No comments yet