prev


Getting Input Values From Keyboard

7.Simple multiplication (22.6.2009)

/*
Program# 7
date : 10-12-2008
Product of two real numbers
*/

#include <stdio.h>
main(){
float a,b,c;
printf("\nEnter values for A and B :");
scanf("%f %f",&a,&b);
c=a*b;
printf("A*B is : %f\n",c);
}

output:
Enter values for A and B : 4.5 3
A*B is : 13.500000

Things to note:
1.The first printf( ) function outputs the message on screen. Using expressions in printf( ) is optional.

2.scanf( ) receives input from keyboard, it is a built-in function. The ampersand (&) before the variables in the scanf( ) function is must. & is an 'Address of ' operator, it gives the location number used by variable in memory. When we say &a, we are telling scanf( ) at which memory location should it store the value supplied by the user from the keyboard.

3. A blank, a tab or a new line must separate the values supplied to scanf( )

4.If a integer value is passed, %f in the scanf( ) function converts and stores the given integer value as a float.
next
blog comments powered by Disqus