The given task is to take an integer as input from the user and print that integer in C language.
In below program, the syntax and procedures to take the integer as input from the user is shown in C language.
- The user enters an integer value when asked.
- This value is taken from the user with the help of scanf() method. The scanf() method, in C, reads the value from the console as per the type specified.
scanf("%X", &variableOfXType); where %X is the format specifier in C It is a way to tell the compiler what type of data is in a variable and & is the address operator in C, which tells the compiler to change the real value of this variable, stored at this address in the memory.
- For an integer value, the X is replaced with type int. The syntax of scanf() method becomes as follows then:
- This entered value is now stored in the variableOfIntType.
- Now to print this value, printf() method is used. The printf() method, in C, prints the value passed as the parameter to it, on the console screen.
- For an integer value, the X is replaced with type int. The syntax of printf() method becomes as follows then:
- Hence, the integer value is successfully read and printed.
Enter the integer: 10 Entered integer is: 10
- How to Read and Print an Integer value in C++
- How to Read and Print an Integer value in Java
- Java Program to Print a Square Pattern for given integer
- Read/Write structure to a file in C
- How to read content of GeeksforGeeks in an organized way?
- Ways to read input from console in Java
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Implement your own tail (Read last n lines of a huge file)
- Input-output system calls in C | Create, Open, Close, Read, Write
- Integer Promotions in C
- Count even and odd digits in an Integer
- How to concatenate two Integer values into one?
- Assigning an integer to float and comparison in C/C++
- String to Integer in Java - parseInt()
- Count the number of holes in an integer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.