APSC 160 Chapter Notes - Chapter 4.5: Scanf Format String, Ampersand

57 views2 pages
31 Aug 2016
School
Department
Course

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.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions