Skip to main content

Read input from the keyboard

To read input from the keyboard, we have to use a pre-defined function "scanf()". The syntax for "scanf()" function is

scanf("format string", arguments list);

A format string can be : %d (integer), %s (string) , %f (floating point number), %c (character) , %lf etc.

Ex : scanf("%d", &input); // for single input
     
Here '%d' represents an integer and 'input' is the name assigned to that integer.

scanf("%d%c", &input1 , &input2 ); // for multiple inputs

To use 'scanf()' function also, we have to include a header file "stdio.h",
i,e #include<stdio.h> or #include"stdio.h"

Comments