Input and Output in C (printf and scanf)
Introduction:-
Input and Output are important concepts in C programming.
Input allows the user to enter data, and output displays the result on the screen.
----------------------------------------------------------------------------------
In C, input and output are handled using functions like printf() and scanf().
Output in C – printf()
The printf() function is used to display output on the screen.
Example:
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
~This program prints “Hello World” on the screen.
----------------------------------------------------------------------------------
Input in C – scanf():-
The scanf() function is used to take input from the user.
Example:
#include <stdio.h>
int main() {
int age;
scanf("%d", &age);
printf("Your age is %d", age);
return 0;
}
This program:
- Takes age as input
- Stores it in a variable
- Prints it on the screen
Format Specifiers in C:-
Format specifiers tell the compiler what type of data is being used.
Data Type | Format Specifier
int | %d
float | %f
char | %c
string | %s
----------------------------------------------------------------------------------
Why Input and Output Are Important:-
- Makes programs interactive
- Allows user data processing
- Essential for real-world applications
Conclusion:-
Understanding printf() and scanf() is necessary for writing interactive C programs.
----------------------------------------------------------------------------------
•After mastering this topic, you can move to operators and expressions.
Comments
Post a Comment