In this tutorial you will learn about the C Program to accept User Input and Print and its application with practical example.
C Program to accept User Input and Print
In this tutorial, we will learn to create a C program that will accept User Input and Print in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C Programming.
What is an integer?
The integer is a positive or negative whole number including zero. These are the number real numbers.
Algorithm to print:-
1 2 3 4 5 6 7 |
1. Declaring the variables for the program. 2. Taking the input from the user in integer and character format. 3. Printing the data taken in input from the user in number and character format. 4. End the program. |
Program to Print Integer
As we all know the integer, character, float, or double value in c programming. In c programming, we can take the input from the user in character & number format. In this program, we will take input in integer format. The second will display the integer & character with the help of a small program. The integer & character are the most useful terminology in any programing language. For number/arithmetic manipulation in c programming, there are many predefined functions available.
With the help of this program, we can accept User Input and Print.
Program Code:–
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/* C Program to accept User Input and Print */ #include <stdio.h> int main() { //declaring the required variables for the program. float num; //num = it will hold the number value char ch; //ch = it will hold the character value /* Taking the Input character from user */ printf("\nPlease enter any Character = "); //Scanning the character input scanf("%c",&ch); printf("The User Enetered Charcater = %c\n", ch); /* Taking the Input number from user */ printf("\nPlease enter any number = "); //Scanning the number input scanf("%f",&num); //Printing the Enetered Float Value to the user. printf("The User Enetered Float Value = %.2f\n", num); return 0;// return 0 to operating system } |
Output:-
In the above program, we have first initialized the required variable.
- num = it will hold the input number value from the user.
- ch = it will hold the character number value from the user.
Taking Input character from the user.
Taking the number value.
Printing the number value.