FORMATTED INPUT AND
OUTPUT IN C
ATUL MALHOTRA
CSE/10/409
INPUT AND OUTPUT
• INPUT:
Input is the process of entering the data into
computers memory
• OUTPUT:
Output is a process of translating data that are in
machine-readable form into a form understandable
by humans or readable by other machines.
I/O FUNCTIONS
• FORMATTED I/O
printf() and scanf()
• CHARACTER I/O
getchar() & putchar()
• STRING I/O
gets() and puts()
Note : To use any of these function first include the appropriate
header file in your program.
FORMATTED I/O
Formatted I/O means to control the type, width,
precision and other attribute of the data during
input and output process. Two functions are
mostly used in C language for this purpose are
– printf()
– scanf()
FORMATTED OUTPUT WITH Printf
Printf FUNCTION
• printf is function used to output any type of
data either characters, strings, numbers etc..
The syntax of printf function is
• printf(“format”, var1, var2,….varn);
• The “format” includes a listing of the data
types of the variables to be output and,
optionally, some text and control character(s).
FORMATTED OUTPUT WITH Printf
• Format Conversion Specifiers:
“%d” -- displays a decimal (base 10) integer
“%l” -- used with other specifiers to indicate a "long"
“%e” -- displays a floating point value in exponential
notation
“%f” -- displays a floating point value
“%g” -- displays a number in either "e" or "f" format
“%c” -- displays a single character
“%s” -- displays a string of characters
• Example:
#include<stdio.h>
#include<conio.h>
main()
{
float a;
int b ;
scanf("%f%d", &a, &b ) ;
printf("You entered %f and %d \n", a, b ) ;
getch();
}
Scanf FUNCTION
• scanf function is used to enter the data into
computers memory through standard input
device generally keyboard. It can be used to
enter multiple data items by a single
statement. The syntax is as follows,
• scanf(“format”,&var1,&var2,….,&varn)
• e.g. scanf(“%d”,&x);
THANK YOU....