1 / 39

Homework 4a and 4b

Homework 4a and 4b. Topics Go over Homework 4a Problems 2.7 - 2.15, Problems 3.11 - 3.13 Go over Homework 4a Problems 4.5 - 4.8. Homework 4a. 2.7 Identify and correct errors: scanf( “d”, value) ; Printf( “The product of %d and %d is %d”<br>, x, y ) ;. Homework 4a.

lsalyers
Télécharger la présentation

Homework 4a and 4b

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework 4a and 4b Topics • Go over Homework 4aProblems 2.7 - 2.15, Problems 3.11 - 3.13 • Go over Homework 4aProblems 4.5 - 4.8

  2. Homework 4a 2.7 Identify and correct errors: • scanf( “d”, value) ; • Printf( “The product of %d and %d is %d”\n, x, y ) ;

  3. Homework 4a 2.7 Identify and correct errors: c. firstNumber + secondNumber = sumOfNumbers d. If ( number => largest ) largest == number ;

  4. Homework 4a 2.7 Identify and correct errors: e. */ Program to determine the largest of three integers /* f. Scanf(“%d”, anInteger);

  5. Homework 4a 2.7 Identify and correct errors: g. printf( “Remainder of %d divided by %d is\n”, x, y, x % y); h. If ( x = y ); printf( %d is equal to %d\n”, x, y );

  6. Homework 4a 2.7 Identify and correct errors: i. print( “The sum is %d\n,” x + y ); j. Printf( “The value you enter is: %d\n, &value );

  7. Homework 4a 2.8 Fill in the blanks: a) _________ are used to document a program and improve its readability. b) The function used to print information on the screen is __________. c) A C statement that makes a decision is ___. d) Calculations are normally performed by _______________ statements. e) The ____________ function inputs values from the keyboard.

  8. Homework 4a 2.9 Write a single C statement; a) Print the message “Enter two numbers.” b) Assign the product of variables b and c to variable a

  9. Homework 4a 2.9 Write a single C statement; c) State that a program performs a sample payroll calculation (i.e., use text that helps to document a program). d) Input three integer values from the keyboard and place these values in integer variables a, b, and c.

  10. Homework 4a 2.10 True or False. a) C operators are evaluated from left to right. b) The following are all valid variable names: _under_bar_, m928134, t5, j7, her_sales, his_account_total, a, b, c, z, z2

  11. Homework 4a 2.10 True or False. c) The statement printf(“a = 5;”); is a typical example of an assignment statement. d) A valid C arithmetic expression containing no parentheses is evaluated from left to right.

  12. Homework 4a 2.10 True or False. e) The following are all invalid variables names: 3g, 87, 67h2, h22, 2h

  13. Homework 4a 2.11 Fill in the blanks. a) What arithmetic operations are on the same level of precedence as multiplication? b) When parentheses are nested, which set of parentheses is evaluated first in an arithmetic expression?

  14. Homework 4a 2.11 Fill in the blanks. 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 ___________.

  15. Homework 4a 2.12 Assume x = 2 and y = 3. Output? a) printf( “%d”, x); b) printf( “%d”, x + x); c) printf( “x=“ ); d) printf( “x=%d”, x);

  16. Homework 4a 2.12 Assume x = 2 and y = 3. Output? e) printf( “%d = %d”, x + y, y + x); f) z = x + y ; g) scanf( “%d%d”, &x, &y ); h) /* printf( “x + y = %d”, x + y); */ i) printf( “\n” );

  17. Homework 4a 2.13 Destructive read-in? a) scanf( “%d%d%d%d%d”, &b,&c,&d,&e,&f); b) P = I + j + k + 7 ; c) printf( “Destructive read-in” ); d) printf( “a = 5”);

  18. Homework 4a 2.14 Given y = ax3 + 7 ; Which are correct? 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 ;

  19. Homework 4a 2.15 State the order of evaluation and find x. a) x = y + 3 * 6 / 2 - 1;

  20. Homework 4a 2.15 State the order of evaluation and find x. b) x = 2 % 2 + 2 * 2 - 2 / 2 ;

  21. Homework 4a 2.15 State the order of evaluation and find x. c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );

  22. Homework 4a 3.11 Identify and correct errors. d) while ( y > 0 ) { printf (“%d\n”, y ); ++y; }

  23. Homework 4a 3.12 Fill in blanks. a) The solution to any problem involves performing a series of actions in a specific ___________. b) A synonym for procedure is ___________. c) A variable that accumulates the sum of several number is a __________. d) The process of setting certain variables to specific values at the beginning of a program is called ________________.

  24. Homework 4a 3.12 Fill in blanks. e) A special value used to indicate “end of data entry” is called a __________________, a __________________, a __________________, or a __________________ value.

  25. Homework 4a 3.12 Fill in blanks. f) A _________________ is a graphical representation of an algorithm. g) In a flowchart, the order in which the steps should be preformed is indicated by _____________________ symbols. h) The termination symbol indicates the _____________ and ___________ of every algorithm.

  26. Homework 4a 3.12 Fill in blanks. i) Rectangle symbols correspond to calculations that are normally performed by ________________ statements and input/output operations that are normally by calls to the ____________ and _________ standard library functions. j) The item written inside a decision symbol is called a ________________.

  27. Homework 4a 3.13 Output of this program? #include <stdio.h> int main () { int x = 1, total = 0, y; while ( x <= 10 ) { y = x * x; printf(“%d\n”, y); total += y; ++x; } printf(“Total is %d\n”, total); return 0; }

  28. Homework 4b 4.5 Identify and correct errors. a) for ( x = 100, x >= 1, x++ ) printf( “%d\n”, x );

  29. Homework 4b 4.5 Identify and correct errors. c) Input is “100 A” and print the input. scanf( “%d”, &intVal ); charVal = getchar(); printf( “Integer: %d\nCharacter: %c\n”, intVal, charVal );

  30. Homework 4b 4.5 Identify and correct errors. d) for ( x = .000001; x <= .0001; x += .000001) printf( “%.7f\n”, x);

  31. Homework 4b 4.5 Identify and correct errors. e) Output the odd integers from 999 to 1. for ( x = 999; x >= 1; x += 2) printf( “%.d\n”, x);

  32. Homework 4b 4.5 Identify and correct errors. f) Output even integers from 2 to 100. counter = 2; Do { if ( counter % 2 == 0) printf( “%.d\n”, counter); counter += 2; } While (counter < 100) ;

  33. Homework 4b 4.5 Identify and correct errors. g) Sum from 100 to 150. for ( x = 100; x <= 150; x ++) ; total += x;

  34. Homework 4b 4.6 Output? a) for ( x = 2; x <= 13; x += 2) printf( “%d\n”, x); b) for ( x = 5; x <= 22; x += 7) printf( “%d\n”, x); c) for ( x = 3; x <= 15; x += 3) printf( “%d\n”, x);

  35. Homework 4b 4.6 Output? d) for ( x = 1; x <= 5; x += 7) printf( “%d\n”, x); e) for ( x = 12; x >= 2; x -= 3) printf( “%d\n”, x);

  36. Homework 4b 4.7 Write for statements. a) 1,2,3,4,5,6,7 b) 3,8,13,18,23

  37. Homework 4b 4.7 Write for statements. c) 20,14,8,2,-4,-10 d) 19,27,35,43,51

  38. Homework 4b 4.8 Output?printf( "Enter two integers in the range 1-20:\n"); scanf("%d%d", &x, &y) ; for ( i = 1; i <= y; i ++) { for (j = 1; j <= x; j++ ) printf( "@"); printf( "\n"); }

  39. Assignment and Next • Read Sections 3.9 – 3.10 Next: • Exam 2 on Wednesday, 11/06. • Project 2 due Sudany, 11/10, midnight.

More Related