Bird
Raised Fist0
Cprogramming~20 mins

Improving code readability - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Readability Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of nested if-else with clear indentation

What is the output of this C code snippet?

C
#include <stdio.h>

int main() {
    int x = 5;
    if (x > 3) {
        if (x < 10) {
            printf("Inside range\n");
        } else {
            printf("Too large\n");
        }
    } else {
        printf("Too small\n");
    }
    return 0;
}
AInside range
BToo large
CToo small
DNo output
Attempts:
2 left
💡 Hint

Check the conditions carefully and follow the indentation to see which block runs.

🧠 Conceptual
intermediate
1:30remaining
Best practice for variable naming

Which variable name is the most readable and follows good naming conventions in C?

Aint numberOfStudents;
Bint x;
Cint n;
Dint a1;
Attempts:
2 left
💡 Hint

Think about names that clearly describe what the variable holds.

🔧 Debug
advanced
2:00remaining
Identify the readability issue in this code

What is the main readability problem in this C code snippet?

C
int main(){int a=10;int b=20;if(a>b){printf("A is bigger\n");}else{printf("B is bigger\n");}return 0;}
AMissing semicolons
BIncorrect use of printf
CLack of spaces and indentation makes it hard to read
DVariables are not declared
Attempts:
2 left
💡 Hint

Look at how the code is spaced and arranged.

📝 Syntax
advanced
1:30remaining
Which option causes a syntax error?

Which of the following C code snippets will cause a syntax error?

Aif (x > 0) printf("Positive\n");
Bif x > 0 { printf("Positive\n"); }
C
if (x &gt; 0)
    printf("Positive\n");
Dif (x > 0) { printf("Positive\n"); }
Attempts:
2 left
💡 Hint

Remember the syntax rules for if statements in C.

🚀 Application
expert
2:00remaining
How many items are printed by this loop?

Consider this C code. How many lines will it print?

C
#include <stdio.h>

int main() {
    for (int i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            printf("%d\n", i);
        }
    }
    return 0;
}
A0
B10
C9
D5
Attempts:
2 left
💡 Hint

Count how many numbers from 0 to 9 are even.

Practice

(1/5)
1. Why is it important to use meaningful variable names in C code?
easy
A. It makes the program run faster.
B. It makes the code easier to understand for others and yourself.
C. It reduces the size of the compiled program.
D. It allows the compiler to optimize memory usage.

Solution

  1. Step 1: Understand variable naming purpose

    Meaningful names describe what the variable holds, making code clearer.
  2. Step 2: Consider code readability impact

    Clear names help anyone reading the code understand its purpose quickly.
  3. Final Answer:

    It makes the code easier to understand for others and yourself. -> Option B
  4. Quick Check:

    Meaningful names improve readability [OK]
Hint: Choose names that describe purpose clearly [OK]
Common Mistakes:
  • Using single letters without context
  • Using vague names like temp or data
  • Ignoring naming conventions
2. Which of the following is the correct way to format an if statement in C for better readability?
easy
A. if (x > 0) { printf("Positive"); }
B. if(x>0){printf("Positive");}
C. if(x > 0)printf("Positive");
D. if ( x>0 ) {printf("Positive");}

Solution

  1. Step 1: Check spacing around operators and keywords

    if (x > 0) { printf("Positive"); } uses spaces after if, around operators, and braces properly.
  2. Step 2: Check consistent brace placement

    if (x > 0) { printf("Positive"); } places braces with spaces, improving readability.
  3. Final Answer:

    if (x > 0) { printf("Positive"); } -> Option A
  4. Quick Check:

    Proper spacing and braces improve readability [OK]
Hint: Use spaces around operators and braces consistently [OK]
Common Mistakes:
  • Skipping spaces after keywords
  • Putting braces on the same line without spaces
  • Omitting braces for single statements
3. What is the output of the following C code snippet?
int main() {
    int a = 5, b = 10;
    int sum = a + b;
    printf("Sum is %d\n", sum);
    return 0;
}
medium
A. Sum is 15
B. Sum is 510
C. Sum is a + b
D. Compilation error

Solution

  1. Step 1: Understand variable initialization and addition

    Variables a and b are assigned 5 and 10, sum is their addition (5 + 10 = 15).
  2. Step 2: Analyze printf output

    printf prints "Sum is " followed by sum's value, which is 15.
  3. Final Answer:

    Sum is 15 -> Option A
  4. Quick Check:

    5 + 10 = 15 output [OK]
Hint: Add variables before printing to get correct sum [OK]
Common Mistakes:
  • Concatenating integers as strings
  • Forgetting to add variables
  • Syntax errors in printf format
4. Identify the readability issue in this C code and select the best fix:
int main(){int x=10;int y=20;if(x>y){printf("x is greater\n");}else{printf("y is greater\n");}return 0;}
medium
A. Use goto statements for flow control.
B. Remove all spaces to make it compact.
C. Change variable names to single letters.
D. Add spaces and line breaks for clarity.

Solution

  1. Step 1: Analyze current formatting

    Code is cramped with no spaces or line breaks, making it hard to read.
  2. Step 2: Suggest formatting improvements

    Adding spaces and line breaks separates statements and improves readability.
  3. Final Answer:

    Add spaces and line breaks for clarity. -> Option D
  4. Quick Check:

    Proper formatting improves readability [OK]
Hint: Use indentation and spaces to separate code blocks [OK]
Common Mistakes:
  • Ignoring formatting leads to hard-to-read code
  • Using goto increases complexity
  • Making names less descriptive
5. You have a function that calculates the area of a rectangle:
float area(float w, float h){return w*h;}

How can you improve this code's readability for a team project?
hard
A. Use single-letter variable names to shorten code.
B. Remove the return statement to simplify.
C. Add descriptive comments and use meaningful parameter names.
D. Write the function in one line without spaces.

Solution

  1. Step 1: Review current function

    Function uses short parameter names and no comments, which may confuse others.
  2. Step 2: Suggest improvements

    Using descriptive names like width and height and adding comments clarifies purpose.
  3. Final Answer:

    Add descriptive comments and use meaningful parameter names. -> Option C
  4. Quick Check:

    Comments and clear names improve teamwork [OK]
Hint: Explain purpose with comments and clear names [OK]
Common Mistakes:
  • Using vague parameter names
  • Skipping comments
  • Making code too compact
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