0
0
Cprogramming~20 mins

Arithmetic operators - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arithmetic Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A6
B7
C5
D4
Attempts:
2 left
💡 Hint
Remember integer division truncates the decimal part.
Predict Output
intermediate
2: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;
}
A10
B11
C13
D12
Attempts:
2 left
💡 Hint
Remember post-increment uses the value before increment, pre-increment increments before use.
Predict Output
advanced
2: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;
}
A-3 -1
B-3 2
C-2 1
D-2 -1
Attempts:
2 left
💡 Hint
In C, integer division truncates toward zero and modulus sign matches the dividend.
🔧 Debug
advanced
2: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;
}
ASyntaxError: missing operand after '*'
BSyntaxError: stray '*' in program
CSyntaxError: expected expression before ';'
DCompilation error: invalid operands to binary *
Attempts:
2 left
💡 Hint
Look carefully at the arithmetic expression syntax.
🚀 Application
expert
3: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?
A
int count = 0;
while (n &gt; 0) {
    n = n / 10;
    count++;
}
B
int count = 1;
while (n &gt;= 10) {
    n = n % 10;
    count++;
}
C
int count = 0;
while (n != 0) {
    n = n * 10;
    count++;
}
D
int count = 0;
while (n &gt; 0) {
    n = n - 10;
    count++;
}
Attempts:
2 left
💡 Hint
Dividing by 10 removes the last digit of a number.