/* * Chatper 4 * Self Test * By: John Stile */ 1. Rewrite the expression aa*bb+cc to ensure that addition is done first. Answer: aa*(bb+cc) 2. What is printed as the value of xx in the following program? #include // int main(void) { int xx,yy; yy=2; xx=yy*yy*yy; printf("The value of xx is %d\n", xx); return 0; } Answer: Prints "The value of xx is 8" and carrage return. 3. What is the output for the following code fragment? int xx,yy; xx=10; yy=3; if (xx==yy) printf("xx is equal to yy. Right?\n"); else printf("xx is not equal to yy\n"); Answer: prints "xx is not equal to yy" and carrage return. 4. What is the output for the following code fragments? a) int xx,yy; xx=10; yy=xx/4; printf("The value fo yy is %d\n", yy); Answer: Prints "The value of yy is 2" and carrage return. b) int xx,yy; xx=10; yy=15; printf( "The value of yy is %f\n", yy=(float)xx/4); Answer: Print "The value of yy is -0.854771 5. What is wrong with the following? int aa,bb; float average; average=aa+bb/2.0; // division of an int by a float printf("The average of aa and bb is %f\n", average); Answer: initialize aa and bb paranthesis around aa+bb to allow addition before division 6. What is the output by each of the follwoing printf statements? Explain. a) printf("%d \n", 'A' +38); // ascii value of A +38, printed as decimal b) printf("%c \n", 'A' +38); // ascii value of A +38, printed as character c) printf("%d \n", 'Z' -3); // ascii value of Z -3, printed as decimal d) printf("%c \n", 'Z' -3); // ascii value of Z -3, printed as character e) printf("%c \n", 'A' -10); // ascii value of A -10, printed as character f) printf("%c \n", 'Z'+3); // ascii value of Z +3, printed as character 7. What is wrong with the following code? Fix it and make it work; #include #include int main(void) { int xx; xx=3; printf("The value of yy is %f\n", pow(2,xx) ); return 0; }