APSC 160 Chapter Notes - Chapter 4.5: Scanf Format String, Ampersand
Document Summary
If we want user to input the numbers then we have to use scanf() function, which takes input from user. For example, we want user to input three numbers then the code will be: int main(){ int a,b,c; printf( enter three numbers ); scanf( %d %d %d , &a, &b , &c); return 0; %d is the format specifier so that value entered is received as integer and & ampersand is used to indicate a pointer which points to the variable. In this case, it points to variables a, b and c. format specifier for character is %c, for float it is %f, for double it is %1f and for string it is. The value is assigned to a, b and c respectively so scanf() function basically reads number or character from keyboard. The above if-else program can also be written in the following manner: So there are three if statements and if statement is always followed by a condition.