0
0
Cprogramming~10 mins

Why input and output are required in C - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message to the screen.

C
#include <stdio.h>

int main() {
    printf([1]);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"Hello, World!\n"
B'Hello, World!'
Cprint("Hello, World!\n")
DHello, World!
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
2fill in blank
medium

Complete the code to read an integer from the user.

C
#include <stdio.h>

int main() {
    int number;
    scanf([1], &number);
    printf("You entered: %d\n", number);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%f"
B"%s"
Cnumber
D"%d"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong format specifier like %f or %s.
Not using the & operator before the variable.
3fill in blank
hard

Fix the error in the code to correctly read and print a float value.

C
#include <stdio.h>

int main() {
    float value;
    scanf([1], &value);
    printf("Value: %f\n", value);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%f"
Bvalue
C"%d"
D"%c"
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d instead of %f for floats.
Not using & before the variable name.
4fill in blank
hard

Fill both blanks to create a program that reads a character and prints it.

C
#include <stdio.h>

int main() {
    char ch;
    scanf([1], &ch);
    printf([2], ch);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%c"
B"%d"
C"You entered: %c\n"
D"%f"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifiers like %d or %f.
Not matching format specifiers between scanf and printf.
5fill in blank
hard

Fill all three blanks to create a program that reads two integers and prints their sum.

C
#include <stdio.h>

int main() {
    int a, b;
    scanf([1], &a);
    scanf([2], &b);
    printf([3], a + b);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%d"
B"%f"
C"Sum is: %d\n"
D"%c"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifiers like %f or %c.
Forgetting to use & before variables in scanf.