Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read two integers from input.
C++
#include <iostream> int main() { int a, b; std::cin >> [1] >> b; std::cout << a + b << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared.
Mixing variable names.
✗ Incorrect
The variable a is declared and should be used to read the first integer input.
2fill in blank
mediumComplete the code to output the product of two integers.
C++
#include <iostream> int main() { int x = 4, y = 5; std::cout << x [1] y << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Using division or subtraction by mistake.
✗ Incorrect
The multiplication operator * is used to calculate the product of two numbers.
3fill in blank
hardFix the error in the code to correctly read three integers and output their sum.
C++
#include <iostream> int main() { int a, b, c; std::cin >> a >> b >> [1]; std::cout << a + b + c << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not declared.
Typo in variable name.
✗ Incorrect
The variable c is declared and should be used to read the third integer input.
4fill in blank
hardFill both blanks to read two floats and output their average.
C++
#include <iostream> int main() { float [1], [2]; std::cin >> a >> b; std::cout << (a + b) / 2 << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring variables different from those used in input.
Using undeclared variables.
✗ Incorrect
The variables a and b are used to read the two float inputs.
5fill in blank
hardFill all three blanks to read three integers and output their maximum.
C++
#include <iostream> #include <algorithm> int main() { int [1], [2], [3]; std::cin >> x >> y >> z; int max_val = std::max([1], std::max([2], [3])); std::cout << max_val << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using undeclared variables.
Mixing variable names between declaration and usage.
✗ Incorrect
The variables x, y, and z are declared and used to read input and find the maximum.