On lynx, use down arrow to move to the next question or choice. Hit return to make your selection.
On lynx, use down arrow to move to the next question or choice. Hit return to make your selection.
In the following questions, no syntax errors have been put in deliberately. (So, "there is a syntax error" is not the right answer and will receive no credit.) Please mark your final answer clearly. In order to receive partial credit, you must show your work.
int i, j ; for (i = 1 ; i < 5 ; i++) { for (j = 0 ; j <= 5 ; j++) { if ( (i + j) % 2 == 0 ) { printf("X") ; } else { printf("O") ; } } printf("\n") ; }Sample Solution
#include <stdio.h> main() { int a = 1, b = 2, c = 3 ; int *ptr1, *ptr2, *ptr3; ptr1 = &a ; ptr2 = &b ; ptr3 = &c ; *ptr1 = *ptr2 + *ptr3 ; printf("a = %d, b = %d, c = %d\n", a, b, c) ; *ptr2 = *ptr1 + b ; printf("a = %d, b = %d, c = %d\n", a, b, c) ; ptr3 = ptr1 ; printf("a = %d, b = %d, c = %d\n", a, b, c) ; *ptr1 = *ptr2 + *ptr3 ; printf("a = %d, b = %d, c = %d\n", a, b, c) ; }Sample Solution
#include <stdio.h> int palermo (int *, int *) ; int palermo (int *p, int *q) { int b ; b = *p ; *p = *q + 5 ; *q = b + 5 ; printf("palermo: b = %d, *p = %d, *q = %d\n", b, *p, *q) ; return(b) ; } main() { int a = 1, b = 7, c = 4 ; a = palermo(&b, &c) ; printf("main: a = %d, b = %d, c = %d\n", a, b, c) ; }Sample Solution
#include <stdio.h> int bologna(int) ; int a = 1, b = 2, c = 3, d = 4, e = 5 ; int bologna(int c) { int e ; a = c + 1 ; b = c + 2 ; c = c + 3 ; d = c + 4 ; e = c + 5 ; printf("bologna: a=%d, b=%d, c=%d, d=%d, e=%d\n", a, b, c, d, e) ; return(e) ; } main() { int b = 10, c = 11 ; printf("main: a=%d, b=%d, c=%d, d=%d, e=%d\n", a, b, c, d, e) ; c = bologna(a) ; printf("main: a=%d, b=%d, c=%d, d=%d, e=%d\n", a, b, c, d, e) ; }Sample Solution
1 2 3 2 2 3 3 3 3If the user enters 5 as the input, your program should print out:
1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5Sample Solution
Write a function PerfectNumber which takes an integer parameter and returns TRUE if the parameter is a perfect number. If the parameter is not a perfect number, the function returns FALSE.