Вы находитесь на странице: 1из 3

Self-Review Exrcises 2.

3: a) int c; int thisVariable; int q76354; int number; b) printf("Enter a Number : \n"); c) scanf("%d", &a); d) if (number != 7) printf("The Numbser is not equal to 7."); e) printf("This is a C Program); f) printf("This is a C\nProgram"); g) printf("This\nis\na\nC\nprogram."); h) printf("This\tis\ta\tC\tProgram."); 2.4: a) /* This program will calculate the product of three integers */ b) int x, y, z; int result; c) printf("Enter three integers: "); d) scanf("%d%d%d", &x, &y, &z); e) result = x * y * z; f) printf("THe product is %d", result); 2.5: /* This program will calculate the product of three integers. */ #include <stdio.h> // START of the main function, to start the entire execution int main(void // main recieves no parameters { int x, y, z; // three integers to be read from user int result; // product of x, y & z printf("Enter three integers: "); // prompt the user to input numbers scanf("%d%d%d", &x, &y, &z); // read the entered nums and store them i n vars result = x * y * z; printf ("The product is %d\n", result); return 0;; } // END of the main function 2.6: a) printf("The value is %d\n", number); error is "&number" b) scanf("%d%d", &number1, &number2); error is "number2" without "&" c) if (c < 7){ error is ";" after the right parathanses printf("C is less than 7\n"); } d) if (c >= 7){ error is =>, it must be corrected as >= printf("C is equal or less than 7\n"); } 2.7:

a) b) c) d) e) f) g) h) i) j)

scanf("%d", &value); printf("The product of %d and %d is %d\n", x, y, (x*y)); sumOfNumbers = firstNumber + secondNumber; if (number >= largest) largest = number; /* Program to determine the largest of three integers */ scanf("%d", &anInteger); printf("Remainder of %d devided by %d is %d\n", x, y, (x%y)); if (x == y) printf("%d is equal to %d\n", x, y); printf("The sum is %d\n", x+y); printf("The value you entered is: %d\n", value);

2.8: a) comments b) printf() c) if d) execution e) scanf() 2.9: a) printf("Enter two numbers."); b) a = b * c; c) /* A Program to perform a sample payroll calculation */ d) scanf("%d%d%d", &a, &b, &c); 2.10: a) True b) True c) False d) False 2.11: a) Division, Remainder b) The innermost parentheses c) 2.12: a) 2 b) 4 c) x= d) x=2 e) 5 = 5 f) Nothing g) Nothing h) Nothing i) Nothing but a new line 2.13: a) scanf("%d%d%d%d%d", &b, &c, &d, &e, &f); 2.14: a), d) and e) 2.15: a) x = x = x = x = b) x = x = x = 7 + 18 / 2 -1; 7 + 9 - 1; 16 - 1; 15; 0 + 4 - 1 4-1; 3;

c) x x x x x

= = = = =

(3 * 9 * (3 + (9 * 3 / (3)))); (3 * 9 * (3 + (9 * 3 / 3))); (3 * 9 * (3 + (9))); (3 * 9 * 12); (27 * 12); ===

Вам также может понравиться