Input / Output Statements

Input / Output Statements

  • Every computer program require input and output function to enter and display the output.
  • The users have to enter the data that will be stored in the memory of computer, process the data and finally display the result .
  • #include<stdio.h>  header file is used for the input / output function.

Input/ output instruction:  This type of instruction are used to perform the function of supplying the input data to program and obtaining the output results from it.

Standard input/output functions.  

scanf() function :  The scanf() function is used to accept input data from the standard device i.e.  keyboard in a fixed format.

Syntax:  scanf(“format string”,arguments);

Format string contains the format specifiers which begin with character ‘%’ and another character according to data type.

Format specifier Input types Data type
%d or %i

%u

%ld

%lu

%x

%o

Short signed integer

Short unsigned integer

Long signed integer

Long unsigned integer

Unsigned hexadecimal integer

Unsigned octal integer

integer
%f

%lf

Single precision float

Double precision float

float
%c

%c

Signed character

Unsigned character

Character
%s string string

 

 

printf() function

This function is used to output data from the computer on to  standard output device in a fixed format.

Syntax:

Printf(“format string”,argument);

Demonstration for input / output function

#include<stdio.h>
#include<conio.h>
void main()
{
int a ;
printf(“enter any number :”);
scanf(“%d”,&a);
printf(“enterd number is = %d”,a);
getch();
}

Flow of program :
Enter any number : 5
Entered number is = 5