Introduction
Formatted input and output in C are essential for displaying data in a readable format and capturing user input efficiently. These operations are handled using the printf() and scanf() functions.

This article covers the syntax, examples, key features, and common issues related to these functions, ensuring an easy-to-understand guide for beginners.
Formatted Output Using printf()
The printf() function is used to display formatted output on the screen.
Syntax
printf("format string", argument1, argument2, ...);
- format string: A string that contains text and format specifiers.
- arguments: The values that replace the format specifiers.
Format Specifiers
- %d - Integer
- %f - Floating-point number
- %c - Character
- %s - String
Example
Explanation
- printf("Name: %s\n", name);: This prints the string stored in name.
- printf("Age: %d\n", age);: This prints the integer value stored in age.
- printf("Height: %.1f\n", height);: This prints the float value stored in height with one decimal place.
- printf("Grade: %c\n", grade);: This prints the character stored in grade.
Output
Name: John
Age: 20
Height: 5.9
Grade: AFormatted Input Using scanf()
The scanf() function reads formatted input from the standard input (keyboard).
Syntax
scanf("format string", &argument1, &argument2, ...);
- format string: A string that contains format specifiers.
- arguments: Pointers to variables where the input values will be stored.
Format Specifiers
- %d - Integer
- %f - Floating-point number
- %c - Character
- %s - String
Example
Explanation
- scanf("%s", name);: Reads a string from the input and stores it in name.
- scanf("%d", &age);: Reads an integer from the input and stores it in age.
- scanf("%f", &height);: Reads a float value from the input and stores it in height.
- scanf(" %c", &grade);: Reads a character from the input and stores it in grade. The space before %c is used to consume any leftover whitespace.
Output (example input in italics):
Enter your name: John
Enter your age: 20
Enter your height: 5.9
Enter your grade: A
Name: John, Age: 20, Height: 5.9, Grade: A




