Input and Output PDF
Input and Output PDF
Presentation by:
Bhumika Sunar
Deepanjali Shrestha
Ragini Yadav
What is Input and Output?
Input:
When we say Input, it means to feed some data into a program.
An input can be given in the form of a file or from the command line.
C programming provides a set of built-in functions (i.e. scanf, printf, strcpy) to read the
given input and feed it to the program as per requirement.
Output:
When we say Output, it means to display some data on screen, printer, or in any file.
C programming provides a set of built-in functions to output the data on the computer
screen as well as to save it in text or binary files.
Types of I/O functions in C
1. Unformatted I/O Functions.
2. Formatted I/O Functions.
getch() putch()
getchar() putchar() Unformatted output functions
Output:
Output:
Enter the character: abcd
Enter the character: abcd
a
Entered character is: a
gets() puts()
Output:
Enter the character : this is presentation
Entered character is: this is presentation
Formatted I/O Functions:
Formatted I/O functions are used to take various inputs from the user
and display multiple outputs to the user.
These functions can help to display the output to the user in different
formats using the format specifiers.
Format specifiers:
In C, the basic data types like int, float, and char each has specific
format specifiers that should be used with functions like scanf() and
printf() for input and output.
These format specifiers ensure that the data is interpreted and
displayed correctly, and they are an essential part of input and output
operations in C.
Format Specifier Datatype Used for
printf():
printf() function is used to display any value like float,
integer, character, string, etc. on the console screen.
It is a pre-defined function that is already declared in the
stdio.h(header file).
Syntax:
To display any variable value:
printf(“Format Specifier”, var1, var2, …., varn);
(%d, %f, %s, %c, etc.)
scanf():
scanf() function is used for reading or taking any value from the keyboard by the
user, these values can be of any data type like integer, float, character, string, and
many more.
This function is declared in stdio.h(header file), that’s why it is also a pre-defined
function.
In scanf() function, we use &(address-of operator) which is used to store the
variable value on the memory location of that variable.
Syntax:
scanf(“Format Specifier”, &var1, &var2, …., &varn);
(%d, %f, %s, %c, etc.)
For example,
• Integer
Input: scanf(“ %d ", &intVariable);
Output: printf(“ %d ", intVariable);
• Float
Input: scanf(“ %f ", &floatVariable);
Output: printf(“ %f ", floatVariable);
• Character
Input: scanf(“ %c ", &charVariable);
Output: printf(“ %c ", charVariable);
// C program to show input and output
#include <stdio.h> while((getchar())!='\n');
// Integer return 0;
printf("Enter the integer: "); }
scanf( "%d", &num);
format specifier address-of operator