Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
■ Contents
■Chapter ■ 3: Programs with Sequence Logic 47
3.1 Introduction .............................................................................................................. 47
3.2 Read Data Supplied by a User .................................................................................. 47
3.3 scanf ....................................................................................................................... 50
3.3.1 Read Data Into a f loat Variable ................................................................................................. 52
3.3.2 Read Data Into a double Variable ............................................................................................... 52
3.4 Read Strings ............................................................................................................. 54
3.5 Examples .................................................................................................................. 55
3.5.1 Problem 1 - Average .................................................................................................................... 55
3.5.2 Problem 2 - Square ..................................................................................................................... 56
3.5.3 Problem 3 - Banking .................................................................................................................... 57
3.5.4 Problem 4 – Tickets ..................................................................................................................... 60
■Chapter ■ 4: Programs with Selection Logic 65
4.1 Introduction .............................................................................................................. 65
4.2 Boolean Expressions ................................................................................................ 65
4.2.1 AND, &&........................................................................................................................................ 66
4.2.2 OR, ||............................................................................................................................................ 67
4.2.3 NOT, !........................................................................................................................................... 68
4.3 The if Construct ...................................................................................................... 69
4.3.1 Find the Sum of Two Lengths ...................................................................................................... 72
4.4 The if...else Construct ....................................................................................... 75
4.4.1 Calculate Pay............................................................................................................................... 77
4.5 On Program Testing .................................................................................................. 80
4.6 Symbolic Constants .................................................................................................. 80
4.6.1 The #define Directive .................................................................................................................. 81
4.6.2 Example – Symbolic Constants ................................................................................................... 82
4.7 More Examples ......................................................................................................... 83
4.7.1 Print a Letter Grade ..................................................................................................................... 83
4.7.2 Classify a Triangle ........................................................................................................................ 85
ix
www.it-ebooks.info