C Programming language

adplus-dvertising
Receiving input in C
Previous Home Next

Receiving input

To make the program general the program itself should ask the user to supply the values through the keyboard during execution. This can be achieved using a function called scanf( ). This function is a counter-part of the printf( ) function. printf( ) outputs the values to the screen whereas scanf( ) receives them from the keyboard. This is illustrated in the program shown below:

/* Calculation of simple interest */
/* Author gekay Date 25/05/2004 */
main( )
{
int p, n ;
float r, si ;
printf ( "Enter values of p, n, r" ) ;
scanf ( "%d %d %f", &p, &n, &r ) ;
si = p * n * r / 100 ;
printf ( "%f" , si ) ;
}

In the above program the first printf( ) outputs the message 'Enter values of p, n, r' on the screen. The value of the program can be received by the function scanf( )

Previous Home Next