Input Output Stmt1
Input Output Stmt1
The single character can be read from the terminal using the getchar function.
In addition, a scanf function can input strings containing more than one character.
%ws or %wc
20 150. 25 motor
20 mot or 150.25
This is because the function would encounter a string when it was expecting a floating-point
value and would therefore terminate Its scan after reading the first value.
Table: Commonly used scanf format codes.
Given below are some of the general points to keep in mind while
writing a scanf Statement
The use of printf function for printing captions and numerical results.
It is highly desirable that the outputs are produced in such a way that they are
understandable and are in an easy-to-use form.
It is therefore necessary for the programmer to give careful consideration to
the appearance and clarity of the output produced by his program.
The printf statement provides certain features that can be effectively exploited
to control the alignment and spacing of print-outs on the terminals.
The general form of printf statement is
printf(“control string”, arg1, arg2, ….., argn);
Control string consists of following three types of items:
1. Characters that will be printed on the screen as they appear.
2. Format specifications that define the output format for display of each item.
3. Escape sequence characters such as \n, \t, and \b.
Some examples of formatted printf statement are:
printf (“ programming in c”);
printf (“ “);
printf (“\n”);
printf (“%d”, x);
printf (“a = %f\n b = %f”, a, b);
printf (“ sum = %d”, 1234);
printf (“\n\n”);
2.5.1 Output of Integer Numbers