C How To Program 6th Edition Deitel Pdf

How

C How To Program 6th Edition Deitel Pdf File

C How to Program 7th Edition Deitel Solutions Manual Full clear download (no formatting errors) at: http://testbanklive.com/download/c-how-to-program-7th-edition-deitelsolutions-manual/ C How to Program 7th Edition Deitel Test Bank Full clear download (no formatting errors) at: http://testbanklive.com/download/c-how-to-program-7th-edition-deiteltest-bank/
2 What’s in a name? That which we call a rose By any other name would smell as sweet. —William Shakespeare
When faced with a decision, I always ask, “What would be the most fun?” —Peggy Walker
“Take some more tea,” the March Hare said to Alice, very earnestly. “I’ve had nothing yet,” Alice replied in an offended tone: “so I can’t take more.” “You mean you can’t take less,” said the Hatter: “it’s very easy to take more than nothing.” —Lewis Carroll
High thoughts must have high language. —Aristophanes
Objectives In this chapter, you’ll: ■




Write simple computer programs in C. Use simple input and output statements. Use the fundamental data types. Learn computer memory concepts. Use arithmetic operators.
Introduction to C Programming—Solutions


Learn the precedence of arithmetic operators. Write simple decisionmaking statements.
2
Chapter 2 Introduction to C Programming—Solutions Self-Review Exercises
2
Self-Review Exercises 2.1
2.2
Fill in the blanks in each of the following. a) Every C program begins execution at the function . ANS: main. b) Every function’s body begins with and ends with . ANS: left brace, right brace. c) Every statement ends with a(n) . ANS: semicolon. d) The standard library function displays information on the screen. ANS: printf. e) The escape sequence n represents the character, which causes the cursor to position to the beginning of the next line on the screen. ANS: newline. f) The Standard Library function is used to obtain data from the keyboard. ANS: scanf. g) The conversion specifier is used in a scanf format control string to indicate that an integer will be input and in a printf format control string to indicate that an integer will be output. ANS: %d. h) Whenever a new value is placed in a memory location, that value overrides the previous value in that location. This process is said to be . ANS: destructive. i) When a value is read from a memory location, the value in that location is preserved; this process is said to be . ANS: nondestructive. j) The statement is used to make decisions. ANS: if. State whether each of the following is true or false. If false, explain why. a) Function printf always begins printing at the beginning of a new line. ANS: False. Function printf always begins printing where the cursor is positioned, and this may be anywhere on a line of the screen. b) Comments cause the computer to print the text after the // on the screen when the program is executed. ANS: False. Comments do not cause any action to be performed when the program is executed. They’re used to document programs and improve their readability. c) The escape sequence n when used in a printf format control string causes the cursor to position to the beginning of the next line on the screen. ANS: True. d) All variables must be defined before they’re used. ANS: True. e) All variables must be given a type when they’re defined. ANS: True. f) C considers the variables number and NuMbEr to be identical. ANS: False. C is case sensitive, so these variables are different. g) Definitions can appear anywhere in the body of a function. ANS: False. A variable’s definition must appear before its first use in the code. In Microsoft Visual C++, variable definitions must appear immediately following the left brace that begins the body of main. Later in the book we’ll discuss this in more depth as we encounter additional C features that can affect this issue.
3
2.3
Chapter 2 Introduction to C Programming—Solutions Self-Review Exercises
3
h) All arguments following the format control string in a printf function must be preceded by an ampersand (&). ANS: False. Arguments in a printf function ordinarily should not be preceded by an ampersand. Arguments following the format control string in a scanf function ordinarily should be preceded by an ampersand. We will discuss exceptions to these rules in Chapter 6 and Chapter 7. i) The remainder operator (%) can be used only with integer operands. ANS: True. j) The arithmetic operators *, /, %, + and - all have the same level of precedence. ANS: False. The operators *, / and % are on the same level of precedence, and the operators + and - are on a lower level of precedence. k) A program that prints three lines of output must contain three printf statements. ANS: False. A printf statement with multiple n escape sequences can print several lines. Write a single C statement to accomplish each of the following: a) Define the variables c, thisVariable, q76354 and number to be of type int. ANS: int c, thisVariable, q76354, number;
b) Prompt the user to enter an integer. End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space. ANS: printf( 'Enter an integer: ' );
c) Read an integer from the keyboard and store the value entered in integer variable a. ANS: scanf( '%d', &a );
d) If number is not equal to 7, print 'The
variable number is not equal to 7.'
ANS: if ( number != 7 ) { printf( 'The variable number is not equal to 7.n' ); }
e) Print the message 'This is
a C program.'
on one line.
ANS: printf( 'This is a C program.n' );
f) Print the message 'This is
a C program.'
on two lines so that the first line ends with C.
ANS: printf( 'This is a Cnprogram.n' );
g) Print the message 'This is
a C program.'
with each word on a separate line.
ANS: printf( 'ThisnisnanCnprogram.n' );
h) Print the message 'This is
a C program.'
with the words separated by tabs.
ANS: printf( 'ThististatCtprogram.n' );
2.4
Write a statement (or comment) to accomplish each of the following: a) State that a program will calculate the product of three integers. ANS: // Calculate the product of three integers
b) Define the variables x, y, z and result to be of type int. ANS: int x, y, z, result;
c) Prompt the user to enter three integers. ANS: printf( 'Enter three integers: ' );
d) Read three integers from the keyboard and store them in the variables x, y and z. ANS: scanf( '%d%d%d', &x, &y, &z );
e) Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result. ANS: result = x * y * z;
f) Print 'The
product is'
followed by the value of the integer variable result.
ANS: printf( 'The product is %dn', result );
4
Chapter 2 Introduction to C Programming—Solutions
Exercises
4
2.5 Using the statements you wrote in Exercise 2.4, write a complete program that calculates the product of three integers. ANS:
1 2 3 4 5 6 7 8 9 10 11 12
2.6
// Calculate the product of three integers #include int main( void ) { int x, y, z, result; // declare variables printf( 'Enter three integers: ' ); // prompt scanf( '%d%d%d', &x, &y, &z ); // read three integers result = x * y * z; // multiply values printf( 'The product is %dn', result ); // display result } // end function main
Identify and correct the errors in each of the following statements: a) printf( 'The value is %dn', &number ); ANS: Error: &number. Correction: Eliminate the &. We discuss exceptions to this later. b) scanf( '%d%d', &number1, number2 ); ANS: Error: number2 does not have an ampersand. Correction: number2 should be &number2. Later in the text we discuss exceptions to this. c) if ( c < 7 ); { printf( 'C is less than 7n' ); }
ANS: Error: Semicolon after the right parenthesis of the condition in the if statement.
Correction: Remove the semicolon after the right parenthesis. [Note: The result of this error is that the printf statement will be executed whether or not the condition in the if statement is true. The semicolon after the right parenthesis is considered an empty statement—a statement that does nothing.] d)
if ( c => 7 ) { printf( 'C is greater than or equal to 7n' ); }
ANS: Error: The relational operator => should be changed to >= (greater than or equal to).
Exercises 2.7 Identify and correct the errors in each of the following statements. (Note: There may be more than one error per statement.) a) scanf( 'd', value ); ANS: scanf( '%d', &value );
b)
printf( 'The product of %d and %d is %d'n, x, y );
ANS: printf( 'The product of %d and %d is %dn', x, y, x * y ); c) firstNumber + secondNumber = sumOfNumbers ANS: sumOfNumbers = firstNumber + secondNumber; d) if ( number => largest ) largest number;
ANS: if ( number >= largest ) largest = number;
e)
*/ Program to determine the largest of three integers /*
ANS: /* Program to determine the largest of three integers */
5
Chapter 2 Introduction to C Programming—Solutions
Exercises
f)
Scanf( '%d', anInteger );
g)
printf( 'Remainder of %d divided by %d isn', x, y, x % y );
h)
if ( x = y ); printf( %d is equal
5
ANS: scanf( '%d', &anInteger ); ANS: printf( 'Remainder of %d divided by %d is %dn', x, y, x % y ); to %dn', x, y );
ANS: if ( x y ) printf( '%d is equal to %dn', x, y );
i)
print( 'The sum is %dn,' x + y );
j)
Printf( 'The value you entered is: %dn, &value );
ANS: printf( 'The sum is %dn', x + y ); ANS: printf( 'The value you entered is: %dn', value );
2.8
Fill in the blanks in each of the following: a) are used to document a program and improve its readability. ANS: comments. b) The function used to display information on the screen is . ANS: printf. c) A C statement that makes a decision is . ANS: if.
d) Calculations are normally performed by statements. ANS: assignment. e) The function inputs values from the keyboard. ANS: scanf.
2.9
Write a single C statement or line that accomplishes each of the following: a) Print the message “Enter two numbers.” ANS: printf( “Enter two numbersn” );
b) Assign the product of variables b and c to variable a. ANS: a = b * c;
c) State that a program performs a sample payroll calculation (i.e., use text that helps to document a program). ANS: // Sample payroll calculation program
2.10
2.11
d) Input three integer values from the keyboard and place these values in integer variables a, b and c. ANS: scanf( '%d%d%d', &a, &b, &c ); State which of the following are true and which are false. If false, explain your answer. a) C operators are evaluated from left to right. ANS: False. Some operators are evaluated left to right and others are evaluated from right to left depending on their associativity (see Appendix A). b) The following are all valid variable names: _under_bar_, m928134, t5, j7, her_sales, his_account_total, a, b, c, z, z2. ANS: True. c) The statement printf('a = 5;'); is a typical example of an assignment statement. ANS: False. The statement prints a = 5; on the screen. d) A valid arithmetic expression containing no parentheses is evaluated from left to right. ANS: False. Multiplication, division, and modulus are all evaluated first from left to right, then addition and subtraction are evaluated from left to right. e) The following are all invalid variable names: 3g, 87, 67h2, h22, 2h. ANS: False. Only those beginning with a number are invalid. Fill in the blanks in each of the following:
6
Chapter 2 Introduction to C Programming—Solutions
Exercises
6
a) What arithmetic operations are on the same level of precedence as multiplication? . ANS: division, modulus. b) When parentheses are nested, which set of parentheses is evaluated first in an arithmetic expression? . ANS: The innermost pair of parentheses. c) A location in the computer's memory that may contain different values at various times throughout the execution of a program is called a . ANS: variable. 2.12 What, if anything, prints when each of the following statements is performed? If nothing prints, then answer “Nothing.” Assume x = 2 and y = 3. a) printf( '%d', x ); ANS: 2
b)
printf( '%d', x + x );
c)
printf( 'x=' );
d)
printf( 'x=%d', x );
e)
printf( '%d = %d', x + y, y + x );
f)
z = x + y;
ANS: 4
ANS: x=
ANS: x=2
ANS: 5 = 5
ANS: Nothing. Value of x + y is assigned to z. g) scanf( '%d%d', &x, &y );
ANS: Nothing. Two integer values are read into the location of x and the location of y.
h)
// printf( 'x + y = %d', x + y );
ANS: Nothing. This is a comment.
i)
printf( 'n' );
ANS: A newline character is printed, and the cursor is positioned at the beginning of the
next line on the screen. 2.13 Which, if any, of the following C statements contain variables whose values are replaced? a) scanf( '%d%d%d%d%d', &b, &c, &d, &e, &f ); b) p = i + j + k + 7; c) printf( '%s', Values are replaced.' ); d) printf( 'a = 5' ); ANS: a and b. 2.14 Given the equation y = ax3 + 7, which of the following, if any, are correct C statements for this equation? a) y = a * x * x * x + 7; b) y = a * x * x * ( x + 7 ); c) y = ( a * x ) * x * ( x + 7 ); d) y = ( a * x ) * x * x + 7; e) y = a * ( x * x * x ) + 7; f) y = a * x * ( x * x + 7 ); ANS: a, d, and e. 2.15 State the order of evaluation of the operators in each of the following C statements and show the value of x after each statement is performed. a) x = 7 + 3 * 6 / 2 - 1; ANS: * is first, / is second, + is third, - is fourth and = is last. Value of x is 15. b) x = 2 % 2 + 2 * 2 - 2 / 2; ANS: % is first, * is second, / is third, + is fourth, - is fifth and = is last. Value of x is 3.
7
Chapter 2 Introduction to C Programming—Solutions
Exercises
7
c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ); ANS: 5 6 4 2 3 1. The = evaluates
last. Value of x is 324. 2.16 Write a program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, quotient and remainder of the two numbers. ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Exercise 2.16 Solution #include int main( void ) { int x; // define first number int y; // define second number printf( '%d', 'Enter two numbers: ' ); // prompt user scanf( '%d%d', &x, &y ); // read values from keyboard // output results printf( 'The sum is %dn', x + y ); printf( 'The product is %dn', x * y ); printf( 'The difference is %dn', x - y ); printf( 'The quotient is %dn', x / y ); printf( 'The remainder is %dn', x % y ); } // end main
Enter two numbers: 20 5 The sum is 25 The product is 100 The difference is 15 The quotient is 4 The remainder is 0
2.17 Write a program that prints the numbers 1 to 4 on the same line. Write the program using the following methods. a) Using one printf statement with no conversion specifiers. b) Using one printf statement with four conversion specifiers. c) Using four printf statements. ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13
// Exercise 2.17 Solution #include int main( void ) { printf( '1 2 3 4nn' ); // part a printf( '%d %d %d %dnn', 1, 2, 3, 4 ); // part b printf( printf( printf( printf(
'1 ' ); // part c '2 ' ); '3 ' ); '4n' );
8
14
Chapter 2 Introduction to C Programming—Solutions
Exercises
8
} // end main
1 2 3 4 1 2 3 4 1 2 3 4
2.18 Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter. ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// Exercise 2.18 Solution #include int main( void ) {
int x; // define first number int y; // define second number printf( '%s', 'Enter two numbers: ' ); // prompt scanf( '%d%d', &x, &y ); // read two integers // compare the two numbers if ( x > y ) { printf( '%d is largern', x ); } // end if if ( x < y ) { printf( '%d is largern', y ); } // end if
if ( x y ) { puts( 'These numbers are equal' ); } // end if } // end main
Enter two numbers: 5 20 20 is larger
Enter two numbers: 239 92 239 is larger
Enter two numbers: 17 17 These numbers are equal
9
Chapter 2 Introduction to C Programming—Solutions
Exercises
9
2.19 Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Use only the single-selection form of the if statement you learned in this chapter. The screen dialog should appear as follows: Input three different integers: 13 27 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 27
ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
// Exercise 2.19 Solution #include int main( void ) {
int int int int int
a; // define first integer b; // define second integer c; // define third integer smallest; // smallest integer largest; // largest integer
printf( '%s', 'Input three different integers: ' ); // prompt user scanf( '%d%d%d', &a, &b, &c ); // read three integers // output sum, average and printf( 'Sum is %dn', a + printf( 'Average is %dn', printf( 'Product is %dn',
product of the three integers b + c ); ( a + b + c ) / 3 ); a * b * c );
smallest = a; // assume first number is the smallest if ( b < smallest ) { // is b smaller? smallest = b; } // end if if ( c < smallest ) { // is c smaller? smallest = c; } // end if printf( 'Smallest is %dn' , smallest ); largest = a; // assume first number is the largest if ( b > largest ) { // is b larger? largest = b; } // end if if ( c > largest ) { // is c larger? largest = c; } // end if printf( 'Largest is %dn', largest );
10 Chapter 2 Introduction to C Programming— Solutions
43
Exercises
10
} // end main
2.20 Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area. Use the constant value 3.14159 for π. Perform each of these calculations inside the printf statement(s) and use the conversion specifier %f. [Note: In this chapter, we have discussed only integer constants and variables. In Chapter 3 we will discuss floating-point numbers, i.e., values that can have decimal points.] ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Exercise 2.20 Solution #include int main( void ) { int radius; // circle radius printf( '%s', 'Input the circle radius: ' ); // prompt user scanf( '%d', &radius ); // read integer radius // calculate and output diameter, circumference and area printf( 'nThe diameter is %dn', 2 * radius ); printf( 'The circumference is %fn', 2 * 3.14159 * radius ); printf( 'The area is %fn', 3.14159 * radius * radius ); } // end main
Input the circle radius: 9 The diameter is 18 The circumference is 56.548620 The area is 254.468790
2.21
Write a program that prints a box, an oval, an arrow and a diamond as follows:
********* * * * * * * * * * * * * * * *********
* * * * *
*
*
***
***
*
*
* * * * *
* *** ***** * * * * * *
*
* *
*
*
* * *
* * *
*
*
* *
*
ANS:
1 2 3 4 5 6 7
// Exercise 2.21 Solution #include int main( void ) { printf( '%s', '********* printf( '%s', '* *
*
***
*
* ***
*n' ); * *n' );
11 Chapter 2 Introduction to C Programming— Solutions
8 9 10 11 12 13 14 15
printf( '%s', printf( '%s', printf( '%s', printf( '%s', printf( '%s', printf( '%s', printf( '%s', } // end main
2.22
'* * '* * '* * '* * '* * '* * '*********
* * * * *
*
***
*
* * * * *
Exercises
***** * * * * * *
11
*
*n' ); *n' ); * *n' ); * *n' ); * *n' ); * *n' ); *n' ); *
What does the following code print?
printf( '*n**n***n****n*****n' );
ANS: * ** *** **** *****
2.23 Write a program that reads in three integers and then determines and prints the largest and the smallest integers in the group. Use only the programming techniques you have learned in this chapter. ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
// Exercise 2.23 Solution #include int main( void ) { int largest; // largest integer int smallest; // smallest integer int int1; // define int1 for user input int int2; // define int2 for user input int int3; // define int3 for user input int temp; // temporary integer for swapping printf( '%s', 'Input 3 integers: ' ); // prompt user and read 3 ints scanf( '%d%d%d%d%d', &largest, &smallest, &int1, &int2, &int3 ); if ( smallest > largest ) { // make comparisons temp = largest; largest = smallest; smallest = temp; } // end if if ( int1 > largest ) { largest = int1; } // end if if ( int1 < smallest ) { smallest = int1; } // end if
12 Chapter 2 Introduction to C Programming— Solutions
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Exercises
12
if ( int2 > largest ) { largest = int2; } // end if if ( int2 < smallest ) { smallest = int2; } // end if if ( int3 > largest ) { largest = int3; } // end if if ( int3 < smallest ) { smallest = int3; } // end if printf( 'The largest value is %dn', largest ); printf( 'The smallest value is %dn', smallest ); } // end main
Input 5 integers: 9 4 5 8 7 The largest value is 9 The smallest value is 4
2.24 Write a program that reads an integer and determines and prints whether it is odd or even. [Hint: Use the remainder operator. An even number is a multiple of two. Any multiple of two leaves a remainder of zero when divided by 2.] ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Exercise 2.24 Solution #include int main( void ) { int integer; // integer input by user printf( '%s', 'Input an integer: ' ); // prompt scanf( '%d', &integer ); // read integer // test if integer is even if ( integer % 2 0 ) { printf( '%d is an even integern', integer ); } // end if // test if integer is odd if ( integer % 2 != 0 ) { printf( '%d is an odd integern', integer ); } // end if } // end main
Input an integer: 78 78 is an even integer
13 Chapter 2 Introduction to C Programming— Solutions
Exercises
13
Input an integer: 79 79 is an odd integer
2.25 Print your initials in block letters down the page. Construct each block letter out of the letter it represents as shown below. PPPPPPPPP P P P P P P P P
J
J J
JJ
JJJJJJJ
DDDDDDDDD D D D D D D DDDDD
ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// Exercise 2.25 Solution #include int main( void ) { puts( 'PPPPPPPPP' ); puts( ' P P' ); puts( ' P P' ); puts( ' P P' ); puts( ' P Pn' ); puts( ' JJ' ); puts( ' J' ); puts( 'J' ); puts( ' J' ); puts( ' JJJJJJJn' ); puts( 'DDDDDDDDD' ); puts( 'D D' ); puts( 'D D' ); puts( ' D D' ); puts( ' DDDDD' ); } // end main
2.26 Write a program that reads in two integers and determines and prints if the first is a multiple of the second. [Hint: Use the remainder operator.] ANS:
1
// Exercise 2.26 Solution
14 Chapter 2 Introduction to C Programming— Solutions
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Exercises
14
#include int main( void ) { int integer1; // first integer int integer2; // second integer printf( '%s', 'Input two integers: ' ); // prompt user scanf( '%d%d', &integer1, &integer2 ); // read two integers // use remainder operator if ( integer1 % integer2 0 ) { printf( '%d is a multiple of %dn', integer1, integer2 ); } // end if if ( integer1 % integer2 != 0 ) { printf( '%d is not a multiple of %dn', integer1, integer2 ); } // end if } // end main
Input two integers: 88 11 88 is a multiple of 11 Input two integers: 777 5 777 is not a multiple of 5
2.27 Display the following checkerboard pattern with eight printf statements and then display the same pattern with as few printf statements as possible. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13
// Exercise 2.27 Solution #include int main( void ) { puts( 'With eight printf() statements:' ); printf( printf( printf( printf( printf( printf(
'%s', '%s', '%s', '%s', '%s', '%s',
'* * * * * * * *n' ); ' * * * * * * * *n' ); '* * * * * * * *n' ); ' * * * * * * * *n' ); '* * * * * * * *n' ); ' * * * * * * * *n' );
15 Chapter 2 Introduction to C Programming— Solutions
14 15 16 17 18 19 20 21 22 23
printf( printf(
Exercises
15
'%s', '* * * * * * * *n' ); '%s', ' * * * * * * * *n' );
puts( 'nNow with one printf() statement:' ); printf(
'%s', '* '* * * * * '* * * * * '* * * * * } // end main
* * * *
* * * *
* * *n *n *n
* * * *
* * * *
*n * * * * * *
* * * *
* * * *
* * * *
* * * * *n' *n' *n' *n' );
With eight printf() statements: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Now with one printf() statement: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2.28 Distinguish between the terms fatal error and nonfatal error. Why might you prefer to experience a fatal error rather than a nonfatal error? ANS: A fatal error causes the program to terminate prematurely. A nonfatal error occurs when the logic of the program is incorrect, and the program does not work properly. A fatal error is preferred for debugging purposes. A fatal error immediately lets you know there is a problem with the program, whereas a nonfatal error can be subtle and possibly go undetected. 2.29 Here’s a peek ahead. In this chapter you learned about integers and the type int. C can also represent uppercase letters, lowercase letters and a considerable variety of special symbols. C uses small integers internally to represent each different character. The set of characters a computer uses together with the corresponding integer representations for those characters is called that computer’s character set. You can print the integer equivalent of uppercase A, for example, by executing the statement printf( '%d', 'A' );
Write a C program that prints the integer equivalents of some uppercase letters, lowercase letters, digits and special symbols. As a minimum, determine the integer equivalents of the following: A B C a b c 0 1 2 $ * + / and the blank character. ANS:
1 2 3
// Exercise 2.29 Solution #include
16 Chapter 2 Introduction to C Programming— Solutions
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 A’s B’s C’s a’s b’s c’s 0’s 1’s 2’s $’s *’s +’s /’s The
Exercises
16
int main( void ) { printf( 'A's integer equivalent is %dn', 'A' ); printf( 'B's integer equivalent is %dn', 'B' ); printf( 'C's integer equivalent is %dn', 'C' ); printf( 'a's integer equivalent is %dn', 'a' ); printf( 'b's integer equivalent is %dn', 'b' ); printf( 'c's integer equivalent is %dn', 'c' ); printf( '0's integer equivalent is %dn', '0' ); printf( '1's integer equivalent is %dn', '1' ); printf( '2's integer equivalent is %dn', '2' ); printf( '$'s integer equivalent is %dn', '$' ); printf( '*'s integer equivalent is %dn', '*' ); printf( '+'s integer equivalent is %dn', '+' ); printf( '/'s integer equivalent is %dn', '/' ); printf( 'The blank character’s integer equivalent is %dn', ’ ’ ); } // end main integer equivalent is 65 integer equivalent is 66 integer equivalent is 67 integer equivalent is 97 integer equivalent is 98 integer equivalent is 99 integer equivalent is 48 integer equivalent is 49 integer equivalent is 50 integer equivalent is 36 integer equivalent is 42 integer equivalent is 43 integer equivalent is 47 blank character’s integer equivalent is 32
2.30 Write a program that inputs one five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each. [Hint: Use combinations of integer division and the remainder operation.] For example, if the user types in 42139, the program should print 4
2
1
3
9
ANS:
1 2 3 4 5 6 7 8 9 10 11
// Exercise 2.30 Solution #include int main( void ) { int number; // number input by user int temp; // temporary integer printf( '%s', 'Enter a five-digit number: ' ); // prompt user scanf( '%d', &number ); // read integer
17 Chapter 2 Introduction to C Programming— Solutions
12 13 14 15 16 17 18 19 20 21 22 23 24 25
Exercises
17
printf( '%d ', number / 10000 ); // print leftmost digit temp = number % 10000; printf( ' %d ', temp / 1000 ); temp = temp % 1000; printf( ' %d ', temp / 100 ); temp = temp % 100; printf( ' %d ', temp / 10 ); temp = temp % 10; printf( ' %dn', temp ); // print right-most digit } // end main
Enter a five-digit number: 23456 2 3 4 5 6
2.31 Using only the techniques you learned in this chapter, write a program that calculates the squares and cubes of the numbers from 0 to 10 and uses tabs to print the following table of values: number 0 1 2 3 4 5 6 7 8 9 10
square 0 1 4 9 16 25 36 49 64 81 100
cube 0 1 8 27 64 125 216 343 512 729 1000
ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Exercise 2.31 Solution #include int main( void ) { int count = 0; // initialize count to zero // calculate the squares and cubes for the numbers 0 to 10 puts( 'nnumbertsquaretcube' ); printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; // increment count by 1 printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count,
18
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
Chapter 2 Introduction to C Programming—Solutions Making a Difference
18
count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); count = count + 1; printf( '%dt%dt%dn', count, count * count, count * count * count ); } // end main
Making a Difference 2.32 (Body Mass Index Calculator) We introduced the body mass index (BMI) calculator in Exercise 1.11. The formulas for calculating BMI are weightInPounds × 703 -------------------------------------------------------------BMI = -----------hei ghtI nI nc hes × h eight InI nc---------hes or we ightI nKilog rams --------------------------------------------------BMI = -----------------hei ghtI nMeter s × h eight In----------------Mete rs Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index. Also, the application should display the following information from
19
Chapter 2 Introduction to C Programming—Solutions Making a Difference
19
the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI: BMI VALUES Underweight: Normal: Overweight: Obese:
less than 18.5 between 18.5 and 24.9 between 25 and 29.9 30 or greater
[Note: In this chapter, you learned to use the int type to represent whole numbers. The BMI calculations when done with int values will both produce whole-number results. In Chapter 3 you’ll learn to use the double type to represent numbers with decimal points. When the BMI calculations are performed with doubles, they’ll both produce numbers with decimal points—these are called “floating-point” numbers.] ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
// Exercise 2.32 Solution: BMI.c // Making a Difference: Body Mass Index Calculator #include //function main begins program execution int main ( void ) { int weight; // weight of the person int height; // height of the person int BMI; // user's BMI // get user's height printf( '%s', 'Please enter your height (in inches): ' ); scanf( '%d', &height ); // get user's weight printf( 'Please enter your weight (in pounds): ' ); scanf( '%d', &weight ); BMI = weight * 703 / ( height * height ); // calculate BMI printf( 'Your BMI is %dnn', BMI ); // output BMI // output data to user puts( 'BMI VALUES' ); puts( 'Underweight:tless than 18.5' ); puts( 'Normal:ttbetween 18.5 and 24.9' ); puts( 'Overweight:tbetween 25 and 29.9' ); puts( 'Obese:tt30 or greater' ); } // end main
20
Chapter 2 Introduction to C Programming—Solutions Making a Difference
20
Please enter your height (in inches): 69 Please enter your weight (in pounds): 155 Your BMI is 22 BMI VALUES Underweight: Normal: Overweight: Obese:
less than 18.5 between 18.5 and 24.9 between 25 and 29.9 30 or greater
2.33 (Car-Pool Savings Calculator) Research several car-pooling websites. Create an application that calculates your daily driving cost, so that you can estimate how much money could be saved by car pooling, which also has other advantages such as reducing carbon emissions and reducing traffic congestion. The application should input the following information and display the user’s cost per day of driving to work: a) Total miles driven per day. b) Cost per gallon of gasoline. c) Average miles per gallon. d) Parking fees per day. e) Tolls per day. ANS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Exercise 2.33 Solution // Making a Difference: Car-Pool Savings Calculator #include // function main begins program execution int main ( void ) { int miles; // total miles driven per day int gasCost; // cost per gallon of gasoline int mpg; // average miles per gallon int parkFee; // parking fees per day int tolls; // tolls per day int total; // total cost // get total miles driven printf( '%s', 'Please enter the total miles driven per day: ' ); scanf( '%d', &miles ); // get cost of gas printf( '%s', 'Please enter the cost per gallon of gasoline: ' ); scanf( '%d', &gasCost ); // get average miles per gallon printf( '%s', 'Please enter average miles per gallon: ' ); scanf( '%d', &mpg ); // get parking fees per day printf( '%s', 'Please enter the parking fees per day: ' ); scanf( '%d', &parkFee ); // get cost of tolls per day printf( '%s', 'Please enter the tolls per day: ' );
21
33 34 35 36 37 38 39
Chapter 2 Introduction to C Programming—Solutions Making a Difference
21
scanf( '%d', &tolls ); // calculate total cost total = tolls + parkFee + ( miles / mpg ) * gasCost; printf( 'Your daily cost of driving to work is $%dn', total ); } // end main
Please enter the total miles driven per day: 100 Please enter the cost per gallon of gasoline: 3 Please enter average miles per gallon: 19 Please enter the parking fees per day: 3 Please enter the tolls per day: 4 Your daily cost of driving to work is $22
C How to Program 7th Edition Deitel Solutions Manual Full clear download (no formatting errors) at: http://testbanklive.com/download/c-how-to-program-7th-edition-deitelsolutions-manual/ C How to Program 7th Edition Deitel Test Bank Full clear download (no formatting errors) at: http://testbanklive.com/download/c-how-to-program-7th-edition-deiteltest-bank/ People also search: c how to program 7th edition pdf solution manual deitel c how to program 8th edition pdf c how to program 7th edition by paul deitel harvey deitel pdf c how to program 10th edition pdf c how to program 9th edition pdf c how to program 6th edition pdf c how to program 8th edition download c how to program pdf free download

Visual C# How to Program (6th Edition) (Deitel Series) PDF Tags Online PDF Visual C# How to Program (6th Edition) (Deitel Series), Read PDF Visual C# How to Program (6th Edition) (Deitel Series), Full PDF Visual C# How to Program (6th Edition) (Deitel Series), All Ebook Visual C# How to Program (6th Edition) (Deitel Series), PDF and EPUB Visual C# How to Program (6th Edition) (Deitel Series), PDF ePub Mobi Visual C# How to Program (6th Edition) (Deitel Series), Reading PDF Visual C# How to Program (6th Edition) (Deitel Series), Book PDF Visual C# How to Program (6th Edition) (Deitel Series), read online Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) Paul J. Deitel pdf, by Paul J. Deitel Visual C# How to Program (6th Edition) (Deitel Series), book pdf Visual C# How to Program (6th Edition) (Deitel Series), by Paul J. Deitel pdf Visual C# How to Program (6th Edition) (Deitel Series), Paul J. Deitel epub Visual C# How to Program (6th Edition) (Deitel Series), pdf Paul J. Deitel Visual C# How to Program (6th Edition) (Deitel Series), the book Visual C# How to Program (6th Edition) (Deitel Series), Paul J. Deitel ebook Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) E-Books, Online Visual C# How to Program (6th Edition) (Deitel Series) Book, pdf Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) E-Books, Visual C# How to Program (6th Edition) (Deitel Series) Online , Read Best Book Online Visual C# How to Program (6th Edition) (Deitel Series), Read Online Visual C# How to Program (6th Edition) (Deitel Series) Book, Read Online Visual C# How to Program (6th Edition) (Deitel Series) E-Books, Read Visual C# How to Program (6th Edition) (Deitel Series) Online , Read Best Book Visual C# How to Program (6th Edition) (Deitel Series) Online, Pdf Books Visual C# How to Program (6th Edition) (Deitel Series), Read Visual C# How to Program (6th Edition) (Deitel Series) Books Online , Read Visual C# How to Program (6th Edition) (Deitel Series) Full Collection, Read Visual C# How to Program (6th Edition) (Deitel Series) Book, Read Visual C# How to Program (6th Edition) (Deitel Series) Ebook , Visual C# How to Program (6th Edition) (Deitel Series) PDF read online, Visual C# How to Program (6th Edition) (Deitel Series) Ebooks, Visual C# How to Program (6th Edition) (Deitel Series) pdf read online, Visual C# How to Program (6th Edition) (Deitel Series) Best Book, Visual C# How to Program (6th Edition) (Deitel Series) Ebooks , Visual C# How to Program (6th Edition) (Deitel Series) PDF , Visual C# How to Program (6th Edition) (Deitel Series) Popular , Visual C# How to Program (6th Edition) (Deitel Series) Read , Visual C# How to Program (6th Edition) (Deitel Series) Full PDF, Visual C# How to Program (6th Edition) (Deitel Series) PDF, Visual C# How to Program (6th Edition) (Deitel Series) PDF , Visual C# How to Program (6th Edition) (Deitel Series) PDF Online, Visual C# How to Program (6th Edition) (Deitel Series) Books Online, Visual C# How to Program (6th Edition) (Deitel Series) Ebook , Visual C# How to Program (6th Edition) (Deitel Series) Book , Visual C# How to Program (6th Edition) (Deitel Series) Full Popular PDF, PDF Visual C# How to Program (6th Edition) (Deitel Series) Read Book PDF Visual C# How to Program (6th Edition) (Deitel Series), Read online PDF Visual C# How to Program (6th Edition) (Deitel Series), PDF Visual C# How to Program (6th Edition) (Deitel Series) Popular, PDF Visual C# How to Program (6th Edition) (Deitel Series) , PDF Visual C# How to Program (6th Edition) (Deitel Series) Ebook, Best Book Visual C# How to Program (6th Edition) (Deitel Series), PDF Visual C# How to Program (6th Edition) (Deitel Series) Collection, PDF Visual C# How to Program (6th Edition) (Deitel Series) Full Online, epub Visual C# How to Program (6th Edition) (Deitel Series), ebook Visual C# How to Program (6th Edition) (Deitel Series), ebook Visual C# How to Program (6th Edition) (Deitel Series), epub Visual C# How to Program (6th Edition) (Deitel Series), full book Visual C# How to Program (6th Edition) (Deitel Series), online Visual C# How to Program (6th Edition) (Deitel Series), online Visual C# How to Program (6th Edition) (Deitel Series), online pdf Visual C# How to Program (6th Edition) (Deitel Series), pdf Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) Book, Online Visual C# How to Program (6th Edition) (Deitel Series) Book, PDF Visual C# How to Program (6th Edition) (Deitel Series), PDF Visual C# How to Program (6th Edition) (Deitel Series) Online, pdf Visual C# How to Program (6th Edition) (Deitel Series), read online Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) Paul J. Deitel pdf, by Paul J. Deitel Visual C# How to Program (6th Edition) (Deitel Series), book pdf Visual C# How to Program (6th Edition) (Deitel Series), by Paul J. Deitel pdf Visual C# How to Program (6th Edition) (Deitel Series), Paul J. Deitel epub Visual C# How to Program (6th Edition) (Deitel Series), pdf Paul J. Deitel Visual C# How to Program (6th Edition) (Deitel Series), the book Visual C# How to Program (6th Edition) (Deitel Series), Paul J. Deitel ebook Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) E-Books, Online Visual C# How to Program (6th Edition) (Deitel Series) Book, pdf Visual C# How to Program (6th Edition) (Deitel Series), Visual C# How to Program (6th Edition) (Deitel Series) E-Books, Visual C# How to Program (6th Edition) (Deitel Series) Online , Read Best Book Online Visual C# How to Program (6th Edition) (Deitel Series)

Contained within each location is an enjoyable activity that teaches and strengthens essential skills. The program also includes a progress checker, which allows teachers and parents to check on the progress of every child using the program, and a sample package of 'Avery Kids' printer supplies that can be used in conjunction with the Art Studio section of the program with gratifying results. Accompanied by our favorite french waif (Madeline) as guide, the user is entreated to enter and explore the many shops and businesses that line 'Main Street'. Many of these activities can be experienced in English, Spanish or French, making the program challenging for older children who want to rehearse their foreign language abilities. Madeline classroom companion 1st &amp; 2nd grade

  • This review is from: Visual C# How to Program (6th Edition) (Deitel Series) (Paperback) Content of the book is okay, not the biggest fan of Pearson. Definitely a good book to get started with programming.
  • Visual C# How to Program, 6/e Millions of students and professionals worldwide have learned programming and software development with Deitel® college textbooks and professional books, LiveLessons™ videos, e-books, REVEL™ interactive multimedia courses, online resource centers and instructor-led corporate training.
  • VISUAL C HOW TO PROGRAM 6TH EDITION DEITEL SERIES Download Visual C How To Program 6th Edition Deitel Series ebook PDF or Read Online books in PDF, EPUB, and Mobi Format. Click Download or Read Online button to VISUAL C HOW TO PROGRAM 6TH EDITION DEITEL SERIES book pdf for free now.
  • 3 product ratings - C++ How to Program, 10th Edition by Deitel Paul and Deitel Harvey $17.35 Trending at $17.85 Trending price is based on prices over last 90 days.
  • C How to Program 7th Edition Deitel Solutions Manual Download at: People also search: c h. Home; Add Document. To program 7th edition by paul deitel harvey deitel pdf c how to program 10th edition pdf c how to program 9th edition pdf c how to program 6th edition pdf c how to program 8th edition download c how to.
Download Visual C How to Program 6th Edition Deitel Series Pub752 Visual C How to Program 6th Edition Deitel Series PDF By Paul Deitel Harvey Deitel READ DOWNLOAD PDF Visual C How to Program 6th Edition Deitel Series FOR ANY DEVICE FULL Get now http bit ly 2BsZuBr For all basic to intermediate lev The professional programmer s Deitel r guide to C 6 and object oriented development for Windows r Written for programmers with a background in high level language PDF Download Visual C How to Program 6th Edition Deitel Series Ebook READ ONLINE Click button below to download or read this book PDF Download Visual C How Java how to program 6th edition how to program deitel pdf to program 6th edition deitel free pdf Deitel Free Download Pdf Book Pdf For Visual Visual C How to Program 6th Edition How to Program 6th Edition Deitel Series hard copy of the book and into my brain so I can download all its Visual C 2010 How to Program 4th Edition PDF Free Download Reviews Read Online ISBN 0132151421 By Harvey Deitel Paul Deitel renowned programming teachers Paul and Harvey Deitel Download Visual C How to Program 6th Edition PDF gt Download E books Visual C How to Program be viewed in full within the software version specified Deitel 174 Series Page Visual Basic 174 2012 How to Program 6 E Visual C

C How to Program 7th Edition Deitel Solutions Manual Download at: People also search: c h. Home; Add Document. Edition by paul deitel harvey deitel pdf c how to program 10th edition pdf c how to program 9th edition pdf c how to program 6th edition pdf c how to program 8th edition download c how to program pdf free.

Book Details

Author : Paul J. Deitel

Pages : 1056 pages

Publisher : Pearson 2016-08-13

When you search for files (video, music, software, documents etc), you will always find high-quality el camino black keys rar files recently uploaded on DownloadJoy or other most popular shared hosts. Download torrent black keys el camino ca. With our unique approach to crawling we index shared files withing hours after Upload. If search results are not what you looking for please give us feedback on where we can/or should improve. As an file sharing search engine DownloadJoy finds el camino black keys rar files matching your search criteria among the files that has been seen recently in uploading sites by our search spider.

Language : English

Book Synopsis

C How To Program 6th Edition Deitel Pdf

For all basic-to-intermediate level courses in Visual C# programming. An informative, engaging, challenging and entertaining introduction to Visual C# Created by world-renowned programming instructors Paul and Harvey Deitel, Visual C# How to Program, Sixth Edition introduces students to the world of desktop, mobile and web app development with Microsoft’s® Visual C#® programming language. Students will use .NET platform and the Visual Studio® Integrated Development Environment to write, test, and debug applications and run them on a wide variety of Windows® devices. At the heart of the book is the Deitel signature live-code approach—rather than using code snippets, the authors present concepts in the context of complete working programs followed by sample executions. Students begin by getting comfortable with the Visual Studio Community edition IDE and basic C# syntax. Next, they build their skills one step at a time, mastering control structures, classes, objects,