Programming in C
80 Chapter 6 Making Decisions which is TRUE if cis within the range of characters 'A'through 'Z'; that is, if cis an uppercase l ...
The ifStatement 81 printf ("Type in your expression.\n"); scanf ("%f %c %f", &value1, &operator, &value2); if ( oper ...
82 Chapter 6 Making Decisions operator with blank spaces when you type in these values. If you had specified the for- mat string ...
The ifStatement 83 if ( operator == '+' ) printf ("%.2f\n", value1 + value2); else if ( operator == '-' ) printf ("%.2f\n", valu ...
84 Chapter 6 Making Decisions The switchStatement The type of if-elsestatement chain that you encountered in the last program ex ...
The switchStatement 85 if ( expression== value1) { program statement program statement ... } else if ( expression== value2) { pr ...
86 Chapter 6 Making Decisions break; case '-': printf ("%.2f\n", value1 - value2); break; case '*': printf ("%.2f\n", value1 * v ...
Boolean Variables 87 switch (operator) { case '*': case 'x': printf ("%.2f\n", value1 * value2); break; } Boolean Variables Many ...
88 Chapter 6 Making Decisions printf ("\n"); return 0; } Program 6.10 Output 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 Several po ...
Boolean Variables 89 “off,” its value is 0. But in C, there is an even more convincing argument in favor of these logic values. ...
90 Chapter 6 Making Decisions To easily test if the value of a flag is FALSE, you can use the logical negation operator, !. In t ...
The Conditional Operator 91 for ( d = 2; d < p; ++d ) if ( p % d == 0 ) isPrime = false; if ( isPrime != false ) printf ("%i ...
92 Chapter 6 Making Decisions The condition x < 0is first tested when the preceding statement is executed. Parentheses are ge ...
Exercises 93 Exercises Type in and run the 10 programs presented in this chapter. Compare the output produced by each program w ...
94 Chapter 6 Making Decisions number. Find out what happens in such a case and then modify the program so that negative numbers ...
7Working with Arrays 7 Working with Arrays THEC LANGUAGE PROVIDES A CAPABILITYthat enables you to define a set of ordered data i ...
96 Chapter 7 Working with Arrays Defining an Array You can define a variable called grades, which represents not a singlevalue o ...
Defining an Array 97 sequences through the first 100 elements of the array grades(elements 0 through 99 ) and adds the value of ...
98 Chapter 7 Working with Arrays Figure 7.1 The array valuesin memory. The elements of arrays declared to be of type int,float, ...
Defining an Array 99 Figure 7.2 valueswith some initialized elements. Program 7.1 Working with an Array include <stdio.h> ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf