computer science
How to Read and Print an Integer Value in C
1. Printing Integer values in C
Approach:
- Store the integer value in the variableOfIntType x.
- Print this value using the printf() method. The printf() method, in C, prints the value passed as the parameter to it, on the console screen.
Syntax:
printf("%d", variableOfIntType);Below is the C program to print the integer value:
- C
Output
Printing Integer value 5
2. Reading Integer values in C
Approach:
- The user enters an integer value when asked.
- This value is taken from the user with the help of the scanf() method. The scanf() method, in C, reads the value from the console as per the type specified.
- For an integer value, the X is replaced with the type int. The syntax of the scanf() method becomes as follows then:
Syntax:
scanf("%d", &variableOfIntType);Below is the C program to read integer values in C:
- C
Output:
Enter the integer: 10 Entered integer is: 10
Learn in a distraction-free environment with refined, high-quality content and 35+ expert-led tech courses to help you crack any interview. From programming languages and DSA to web development and data science, GeeksforGeeks Premium has you covered!
Choose GeeksforGeeks Premium today and also get access to Unlimited Article Summarization, 100% Ad free environment, A.I. Bot support in all coding problems, and much more. Go Premium!
ليست هناك تعليقات:
إرسال تعليق