HOME      |      HTML      |      PHP      |      DREAMWEAVER      |      CSS      |      C      |

Formatted I/O in C :

The formatted Input / Output functions can read and write values of all data types, provided the appropriate conversion symbol is used to identify the datatype.

scanf is used for receiving formatted Input and printf is used for displaying formatted output.

Syntax for scanf :

scanf(“control_string 1, - - , control_string n”,&variable1, - - - - ,variable n);

Syntax for printf :

printf(“control_string 1, - - , control_string n”,variable1, - - - - , variable n);

Sample Program :


void main()
int no;
char ch;
char s[20];

printf("Enter a character : ");

printf("Enter a No : ");

printf("Enter a Word or String : ");

printf("\n Character : %c",ch);
printf("\n No : %d",no);
printf("\n String : %s",s);


Program Algorithm / Explanation

  1. #include<stdio.h> header file is included because, the C in-built statement printf we used in this program comes under stdio.h header files.
  2. #include<conio.h> is used because the C in-built function getch() comes under conio.h header files.
  3. main () function is the place where C program execution begins.
  4. Variable no of type int is declared.
  5. Variable ch of type char is declared.
  6. Array s[] of size 20 and type char is declared.
  7. printf is used to prompt the user to input data to the above variables.
  8. scanf is used to receive the data’s.
  9. Control string %d used for receiving user input for integer data, %c for character and %s for receiving in a array.
  10. The user input data’s are displayed using printf.

Output :

printf and scanf in c