C Managing Input ⁄ Output Operations

 

Formatted Input For Scanf

The formatted input refers to input data that has been arranged in a particular format.
Input values are generally taken by using the scanf function.
The scanf function has the general form.
Scanf (“control string”, arg1, arg2, arg3 ………….argn);
The format field is specified by the control string and the arguments arg1, arg2, …………….argn specifies the addrss of location where address is to be stored.
Example for scan function
scanf (“%3d %4d”, &sum1, &sum2);
If the values input are 175 and 1342 here value 175 is assigned to sum1 and 1342 to sum 2. Suppose the input data was follows 1342 and 175. The number 134 will be assigned to sum1 and sum2 has the value 2 because of %3d the number 1342 will be cut to 134 and the remaining part is assigned to second variable sum2.
If floating point numbers are assigned then the decimal or fractional part is skipped by the computer.
To read the long integer data type we can use conversion specifier % ld & % hd for short integer.

Printing One Line

printf();
The most simple output statement can be produced in C’ Language by using printf statement.
It allows you to display information required to the user and also prints the variables we can also format the output and provide text labels.
The simple statement such as
Printf (“Enter 2 numbers”);

Prompts the message enclosed in the quotation to be displayed.

Use of printf statement

#include ' stdio.h '
main ( ) 
{ 
     printf (“Hello!”); 
	 printf (“Welcome to the world of Engineering!”); 
}
 output:	Hello! Welcome to the world of Engineering. 
        


Make Comments..!!


Oops!! No posts from user.

Download Android App