Top 30 programming questions on Input-Output in C


Q 1. Print "Hello, World!" using `printf`.

Expected Output:

Hello, World!

Q 2. Read an integer from the user and print it.

Expected Output:

Enter an integer: 5

You entered: 5

Q 3. Read two integers from the user and print their sum.

Expected Output:

Enter two integers: 3 7

Sum: 10

Q 4. Read a character from the user and print its ASCII value.

Expected Output:

Enter a character: A

ASCII value of A: 65

Q 5. Read a floating-point number and print it with 2 decimal places.

Expected Output:

Enter a floating-point number: 5.6789

You entered: 5.68

Q 6. Print the value of an integer using `printf` and `%d`.

Expected Output:

Value: 42

Q 7. Read a string from the user and print it.

Expected Output:

Enter a string: Hello

You entered: Hello

Q 8. Read a multi-word string using `gets` and print it using `puts`.

Expected Output:

Enter a string: Hello World

You entered: Hello World

Q 9. Print a number in octal format using `printf`.

Expected Output:

Octal format: 20

Q 10. Print a number in hexadecimal format using `printf`.

Expected Output:

Hexadecimal format: ff

Q 11. Read and print a double value using `%lf`.

Expected Output:

Enter a double value: 3.14159

You entered: 3.141590

Q 12. Read and print an unsigned integer using `%u`.

Expected Output:

Enter an unsigned integer: 4294967295

You entered: 4294967295

Q 13. Use `scanf` to read a date in the format `dd/mm/yyyy` and print it.

Expected Output:

Enter a date (dd/mm/yyyy): 5/9/2023

You entered: 05/09/2023

Q 14. Print a floating-point number in scientific notation using `printf`.

Expected Output:

Scientific notation: 1.234560e+02

Q 15. Read and print a character using `getchar` and `putchar`.

Expected Output:

Enter a character: Z

You entered: Z

Q 16. Read multiple characters using `getchar` and print them.

Expected Output:

Enter characters (end with a period): Hello World.

Hello World

Q 17. Read and print a long integer using `scanf` and `printf`.

Expected Output:

Enter a long integer: 1234567890

You entered: 1234567890

Q 18. Use `fgets` to read a string with spaces and print it.

Expected Output:

Enter a string: Hello World

You entered: Hello World

Q 19. Print a formatted table of numbers and their squares.

Expected Output:

Number  Square

1                        1

2                       4

3                       9

4                       16

5                       25

Q 20. Read and print multiple integers in a loop.

Expected Output:

Enter an integer: 10

You entered: 10

Enter an integer: 20

You entered: 20

Enter an integer: 30

You entered: 30

Q 21. Use `printf` to format and align multiple values.

Expected Output:

Name       Age       Grade

Alice           10             A

Bob             12             B

Charlie       11             C

Q 22. Read and print a hexadecimal number using `%x`.

Expected Output:

Enter a hexadecimal number: a1b

You entered: a1b

Q 23. Print a number with leading zeros using `printf`.

Expected Output:

Padded with zeros: 00042

Q 24. Read and print a floating-point number using `%f`.

Expected Output:

Enter a floating-point number: 7.89

You entered: 7.890000

Q 25. Use `scanf` to read multiple values in one line.

Expected Output:

Enter two integers and a float: 5 10 3.14

You entered: 5 10 3.14

Q 26. Print a value using different format specifiers.

Expected Output:

Decimal: 255, Octal: 377, Hexadecimal: ff

Q 27. Read and print a short integer using `%hd`.

Expected Output:

Enter a short integer: 123

You entered: 123

Q 28. Read and print a signed and unsigned integer.

Expected Output:

Enter a signed integer: -42

Enter an unsigned integer: 42

Signed: -42, Unsigned: 42

Q 29. Use `scanf` to read a character, an integer, and a float.

Expected Output:

Enter a character, an integer, and a float: A 5 4.56

You entered: A, 5, 4.56

Q 30. Print the result of an arithmetic operation using `printf`.

Expected Output:

Sum: 30, Difference: -10, Product: 200

Social Share

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!