0
0
Cprogramming~10 mins

Multiple input and output in C - Interactive Code Practice

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

Complete the code to read two integers from the user.

C
#include <stdio.h>

int main() {
    int a, b;
    printf("Enter two numbers: ");
    scanf([1], &a, &b);
    printf("You entered %d and %d\n", a, b);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%d %d"
B"%s %s"
C"%c %c"
D"%f %f"
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f or %c instead of %d for integers.
Forgetting to use & before variable names in scanf.
2fill in blank
medium

Complete the code to print two floating-point numbers with two decimal places.

C
#include <stdio.h>

int main() {
    float x = 3.1415, y = 2.7182;
    printf([1], x, y);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%c %c\n"
B"%d %d\n"
C"%.2f %.2f\n"
D"%f %f\n"
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d to print floats.
Not specifying decimal places, leading to many decimals.
3fill in blank
hard

Fix the error in the code to correctly read a character and an integer.

C
#include <stdio.h>

int main() {
    char c;
    int n;
    printf("Enter a character and a number: ");
    scanf("%c [1]", &c, &n);
    printf("You entered %c and %d\n", c, n);
    return 0;
}
Drag options to blanks, or click blank then click option'
A%f
B%d
C%c
D%s
Attempts:
3 left
💡 Hint
Common Mistakes
Using %c twice in scanf.
Using %f or %s for integers.
4fill in blank
hard

Fill both blanks to read and print two integers separated by a space.

C
#include <stdio.h>

int main() {
    int a, b;
    printf("Enter two integers: ");
    scanf([1], &a, &b);
    printf([2], a, b);
    return 0;
}
Drag options to blanks, or click blank then click option'
A"%d %d"
B"%f %f"
C"%d %d\n"
D"%c %c"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifiers in scanf or printf.
Forgetting newline in printf.
5fill in blank
hard

Fill all three blanks to read a character, an integer, and a float, then print them.

C
#include <stdio.h>

int main() {
    char ch;
    int num;
    float val;
    printf("Enter a character, an integer, and a float: ");
    scanf([1], &ch, &num, &val);
    printf([2], ch, num, val);
    return [3];
}
Drag options to blanks, or click blank then click option'
A"%c %d %f"
B"%c %d %f\n"
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up format specifiers.
Forgetting newline in printf.
Returning 1 instead of 0.