INPUT & OUTPUT

🖰 C-INPUT & C-OUTPUT 💻

Input means to provide the program with some data to be used in the program and Output means to display data on-screen or write the data to a printer or a file.

C programming language provides many built-in functions to read any given input and to display data on the screen when there is a need to output the result.

In this tutorial, we will learn about such functions, which can be used in our program to take input from the user and to output the result on the screen.

💻C-OUTPUT💻

In C programming, printf() is one of the main output function. The function sends formatted output to the screen. For example,

Example 1: C Output


Output




Example 2: Integer Output



Output



We use %d format specifier to print int types. Here, the %d inside the quotations will be replaced by the value of testInteger.


Example 3: float and double Output



Output


\
To print float, we use %f format specifier. Similarly, we use %lf to print double values.


Example 4: Print Characters



Output



To print char, we use %c format specifier.


🖰 C-INPUT 🖰
In C programming, scanf() is one of the commonly used function to take input from the user. The scanf() function reads formatted input from the standard input such as keyboards.

Example 5: Integer Input/Output



Output



Here, we have used %d format specifier inside the scanf() function to take int input from the user. When the user enters an integer, it is stored in the testInteger variable.


Example 6: Float and Double Input/Output



Output



We use %f and %lf format specifier for float and double respectively.

Example 7: C Character I/O



Output



When a character is entered by the user in the above program, the character itself is not stored. Instead, an integer value (ASCII value) is stored.
And when we display that value using %c text format, the entered character is displayed. If we use %d to display the character, it's ASCII value is printed.

Example 8: ASCII Value



Output



I/O Multiple Values

Here's how you can take multiple inputs from the user and display them.



Output

No comments:

Post a Comment

Please don't comment any spam link in comment.