Challenge - 5 Problems
Arithmetic Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed arithmetic operations
What is the output of this C code snippet?
C
#include <stdio.h> int main() { int a = 5, b = 2; int result = a / b * b + a % b; printf("%d\n", result); return 0; }
Attempts:
2 left
💡 Hint
Remember integer division truncates the decimal part.
✗ Incorrect
The expression evaluates as (5 / 2) * 2 + (5 % 2) = 2 * 2 + 1 = 5.
❓ Predict Output
intermediate2:00remaining
Result of increment and multiplication
What will be printed by this C program?
C
#include <stdio.h> int main() { int x = 3; int y = x++ * 2 + ++x; printf("%d\n", y); return 0; }
Attempts:
2 left
💡 Hint
Remember post-increment uses the value before increment, pre-increment increments before use.
✗ Incorrect
x starts as 3. x++ evaluates to 3 (x becomes 4 after), so x++ * 2 = 6. ++x then increments x to 5 and evaluates to 5. Thus, y = 6 + 5 = 11.
❓ Predict Output
advanced2:00remaining
Division and modulus with negative numbers
What is the output of this C code?
C
#include <stdio.h> int main() { int a = -7, b = 3; printf("%d %d\n", a / b, a % b); return 0; }
Attempts:
2 left
💡 Hint
In C, integer division truncates toward zero and modulus sign matches the dividend.
✗ Incorrect
In C, -7 / 3 = -2 (truncates toward zero), and -7 % 3 = -1 (sign matches dividend).
🔧 Debug
advanced2:00remaining
Identify the error in arithmetic expression
What error will this C code produce when compiled?
C
#include <stdio.h> int main() { int a = 10, b = 3; int c = a / b *; printf("%d\n", c); return 0; }
Attempts:
2 left
💡 Hint
Look carefully at the arithmetic expression syntax.
✗ Incorrect
The expression 'a / b *;' is incomplete because '*' operator lacks a right operand, causing a syntax error.
🚀 Application
expert3:00remaining
Calculate the number of digits in an integer
Which code snippet correctly calculates the number of digits in a positive integer n using arithmetic operators only?
Attempts:
2 left
💡 Hint
Dividing by 10 removes the last digit of a number.
✗ Incorrect
Option A divides n by 10 repeatedly, counting how many times until n is 0, which equals the number of digits.