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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- How to read content of GeeksforGeeks in an organized way?
- Read/Write structure to a file in C
- 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?
- Highest power of 2 less than or equal to given Integer
- String to Integer in Java - parseInt()
- Storage of integer and character values in C
- Check for integer overflow on multiplication
- How to concatenate two integer arrays without using loop in C ?
- Find the missing integer in an array if mean is given
- Input an integer array without spaces in C
- 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 email@example.com. 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.