Introduction
Input and output let a program talk with people or other programs. Input lets the program get information, and output shows results.
Input and output let a program talk with people or other programs. Input lets the program get information, and output shows results.
#include <stdio.h> int main() { int number; printf("Enter a number: "); scanf("%d", &number); // input printf("You entered: %d\n", number); // output return 0; }
printf is used to show output on the screen.
scanf is used to get input from the user.
printf("Hello, World!\n");age.int age; scanf("%d", &age);
char name[20]; scanf("%19s", name);
This program asks the user to enter a number, reads it, and then shows it back.
#include <stdio.h> int main() { int number; printf("Enter a number: "); scanf("%d", &number); printf("You entered: %d\n", number); return 0; }
Always check that input is valid to avoid errors.
Output helps users understand what the program is doing.
Without input and output, programs cannot interact with the outside world.
Input lets programs receive information from users or other sources.
Output lets programs show results or messages.
Both are needed for useful and interactive programs.
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old.\n", age);
return 0;
}#include <stdio.h>
int main() {
int num;
printf("Enter number: ");
scanf("%d", num);
printf("Number is %d\n", num);
return 0;
}Pass the test and this pattern moves unknown