Introduction :
In any programming language, input and output operations are very essential for interacting between the user and the program. In C language, you can do input and output operations using standard input/output library (stdio.h) functions such as printf(), scanf(), getchar(), putchar() etc. In this article, I shall show you how to take input from the user and display output on the console screen in C programming language.
What is the input and output in programming :
The input and output is a basic task in programming world. They allow programs to receive and display data respectively. The input means receive data from external sources. There are different types of input sources you can see such as keyboard, mouse, files, sensors (camera, microphone, etc.), network and more.
The output means display information on the external sources. The common output sources are monitor, printer, files, speakers, network etc. The input and output operations are very useful for creating user friendly application. They allow the application to interact with users, other application and hardware devices.
Different types of input and output in C language :
The following programs are the examples of different types of input and output in C programming language.
Using printf() and scanf() functions :
The printf() and scanf() are the main input and output functions in C programming language. The printf() function is used for display the formatted output (text) on the console screen. The scanf() function is used to take formatted input from the standard input (keyboard). Here, I have shown the example of different data types with code.
Integer number input and output :
In this example, you see the scanf() function reads an integer number from the user and stores it in the int variable (my_number). Then, using the printf() function, displays the value of “my_number” variable on the screen. To run this program, you have to install VS Code in your PC. You have to also set up VS Code for C program.
Now, open VS code and create a file name as “integer_input.c”. After that, copy the following code and paste in the “integer_input.c” file and save it.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main()
{
int my_number;
printf("Enter any number: ");
scanf("%d", &my_number);
printf("Number = %d\n",my_number);
return 0;
}
Output :
When you run the program on your PC, the program asks to enter any integer number. After entering the number, click on the “Enter” button. Now, you can see the output as below image.

Floating point number input and output :
In this example, you see the scanf() function reads a floating point number from the user and stores it in the float variable (float_num). Then, using the printf() function, displays the value of “float_num” variable on the screen. For this, open VS code and create a file name as “float_input.c”. After that, copy the following code and paste in the “float_input.c” file and save it.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main()
{
float float_num;
printf("Enter a number with decimal: ");
scanf("%f", &float_num);
printf("float number = %f\n", float_num);
return 0;
}
Output :
Then, run the program on your PC. Here, the program asks to enter any floating point number. When you enter the floating point number and click on the “Enter” button, you see the output as below image.

Character input and output :
In this example, you see the scanf() function reads a single character from the user and stores it in the char variable (char_input). Then, using the printf() function, displays the value of “char_input” variable on the screen. For this, open VS code and create a file name as “char_input.c”. After that, copy the following code and paste in the “char_input.c” file and save it.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main()
{
char char_input;
printf("Enter a character: ");
scanf("%c",&char_input);
printf("You entered %c\n", char_input);
printf("ASCII value is %d\n", char_input);
return 0;
}
Output :
After that, run the program on your PC. Then, the program asks to enter any character. When you enter the character and click on the “Enter” button, you see the output as below image. Here, I also show you the ASCII value of the character.

The getchar() and putchar() functions :
The getchar() function reads a single character from the standard input (keyboard). The putchar() function displays a single character to the standard output (console). You can use getchar() and putchar() functions for character input from the keyboard and display on the console respectively. For this, open VS code and create a new file name as “getchar_input.c”. Now, copy the following code and paste in “getchar_input.c” file and save it.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main( ) {
int ch;
printf( "Enter a character :");
ch = getchar( );
printf( "\nYou entered: ");
putchar( ch );
printf("\n");
return 0;
}
Output :
Then, run the program. Then, the program asks to enter any character. When, you enter a character and click on the “Enter” button, you see the below image as output. If you enter more than one character, you will see the first one on the output.

The gets() and puts() functions :
The gets() function reads a string from the standard input (keyboard). The puts() function displays a string to the standard output (console). You can use gets() and puts() functions for string input from the keyboard and display on the console respectively. So, you have to open VS code and create a new file name as “gets_input.c”. Now, copy the following code and paste in “gets_input.c” file and save it.
/*Developed by Puskar Jasu*/
#include <stdio.h>
int main( ) {
char my_str[100];
printf( "Enter a string : ");
gets( my_str );
printf( "\nYou entered: ");
puts( my_str );
return 0;
}
Output :
After that, run the program. Now, the program asks you to enter a string. When you enter a string and click on the “Enter” button, you see the output like following image.

Conclusion :
Lastly, you have learned different types of input and output in C programming language. You can use them in your program to get input from users and display the output on the console screen.
Thank you for visiting my site.