Bird
Raised Fist0
Cprogramming~20 mins

Arithmetic operators - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. Which arithmetic operator in C gives the remainder of a division?
easy
A. The multiplication operator (*)
B. The division operator (/)
C. The modulus operator (%)
D. The subtraction operator (-)

Solution

  1. Step 1: Understand the modulus operator

    The modulus operator (%) returns the remainder after division of two integers.
  2. Step 2: Compare with other operators

    Division (/) returns the quotient, multiplication (*) multiplies, subtraction (-) subtracts.
  3. Final Answer:

    The modulus operator (%) -> Option C
  4. Quick Check:

    Remainder = % operator [OK]
Hint: Remainder means modulus (%) operator [OK]
Common Mistakes:
  • Confusing division (/) with modulus (%)
  • Thinking multiplication (*) gives remainder
  • Using subtraction (-) for remainder
2. Which of the following is the correct syntax to multiply two integers a and b in C?
easy
A. a x b;
B. a * b;
C. a . b;
D. a & b;

Solution

  1. Step 1: Recall multiplication operator in C

    The multiplication operator in C is the asterisk symbol (*).
  2. Step 2: Check each option

    a * b; uses '*', which is correct. Options B, C, D use invalid symbols for multiplication.
  3. Final Answer:

    a * b; -> Option B
  4. Quick Check:

    Multiply with * operator [OK]
Hint: Use * for multiplication in C [OK]
Common Mistakes:
  • Using 'x' instead of '*' for multiplication
  • Using '.' or '&' mistakenly
  • Missing semicolon at end
3. What is the output of this C code?
int a = 7, b = 3;
printf("%d", a / b);
medium
A. 1
B. 2.333333
C. 3
D. 2

Solution

  1. Step 1: Understand integer division in C

    Both a and b are integers, so a / b performs integer division, which discards the decimal part.
  2. Step 2: Calculate 7 / 3 using integer division

    7 divided by 3 is 2.333..., but integer division returns 2.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Integer division truncates decimals [OK]
Hint: Integer division drops decimals, result is integer [OK]
Common Mistakes:
  • Expecting floating-point result
  • Confusing remainder with division result
  • Using wrong format specifier in printf
4. Find the error in this C code snippet:
int x = 10;
int y = 3;
int z = x / y.0;
printf("%d", z);
medium
A. Using a floating-point number in integer division
B. Incorrect format specifier in printf
C. Missing semicolon after variable declaration
D. Division by zero error

Solution

  1. Step 1: Analyze the division expression

    The expression x / y.0 uses y.0 which attempts a floating-point literal but causes invalid syntax, as x and y are integers.
  2. Step 2: Understand the syntax error

    Using y.0 causes a compilation error due to invalid syntax in the integer division context.
  3. Final Answer:

    Using a floating-point number in integer division -> Option A
  4. Quick Check:

    Integer division must use integers only [OK]
Hint: Integer division needs integer operands only [OK]
Common Mistakes:
  • Thinking printf format is wrong
  • Ignoring the decimal in y.0
  • Assuming division by zero
5. You want to calculate the average of two integers a and b in C and get a floating-point result. Which code snippet correctly does this?
hard
A. float avg = (a + b) / 2.0;
B. float avg = (a + b) / 2;
C. int avg = (a + b) / 2.0;
D. float avg = a / b + 2;

Solution

  1. Step 1: Understand integer vs floating-point division

    Dividing by 2 (integer) causes integer division, losing decimals. Dividing by 2.0 (double) forces floating-point division.
  2. Step 2: Check each option for correct average calculation

    float avg = (a + b) / 2; does integer division then converts to float, losing decimals. float avg = (a + b) / 2.0; divides by 2.0, giving float result. int avg = (a + b) / 2.0; stores float result in int, losing decimals. float avg = a / b + 2; is incorrect formula.
  3. Final Answer:

    float avg = (a + b) / 2.0; -> Option A
  4. Quick Check:

    Divide by 2.0 for float average [OK]
Hint: Divide by 2.0 to get float average [OK]
Common Mistakes:
  • Dividing by integer 2 causing integer division
  • Storing float result in int variable
  • Wrong formula for average
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard