0
0
Cprogramming~5 mins

Why input and output are required in C

Choose your learning style9 modes available
Introduction

Input and output let a program talk with people or other programs. Input lets the program get information, and output shows results.

When you want the user to enter their name or age.
When a program needs to read data from a file or keyboard.
When you want to show results or messages on the screen.
When a program sends data to another program or device.
When debugging to see what the program is doing.
Syntax
C
#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.

Examples
Prints a message to the screen.
C
printf("Hello, World!\n");
Reads an integer input from the user and stores it in age.
C
int age;
scanf("%d", &age);
Reads a string input (up to 19 characters) from the user.
C
char name[20];
scanf("%19s", name);
Sample Program

This program asks the user to enter a number, reads it, and then shows it back.

C
#include <stdio.h>

int main() {
    int number;
    printf("Enter a number: ");
    scanf("%d", &number);
    printf("You entered: %d\n", number);
    return 0;
}
OutputSuccess
Important Notes

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.

Summary

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.