/* * Chapter4 * Assingment * John Stile */ 1. What is printed as the value of x in the following program? #include int main(void) { int xx,yy; yy=2; xx=5; yy=yy*yy; // 2*2=4. assign 4 to yy xx=(yy+4)*(xx-2); // add 4+4=8. 5-2=3, multipy 8*3=24 printf("The value of xx is %d\n", xx); return 0; } Answer: 24 2. What is the output from the following code fragment? int xx,yy; xx=10; yy=3; printf("value of xx is %d\n", xx=3); if(xx==yy) printf("xx is equal to yy.\n"); else printf("xx is not equal to yy.\n"); Answer: Print "value of xx is 3" and carrage return Print "is not equal to yy" 3. Fix the following code fragment: int aa,bb; float xx,yy; aa=27; bb=13; xx=(float)aa/(bb-4); printf("xx is now %f \n", xx); 4. Write a short program that asks the user for an integer then asks for a second integer. The program then determins the relationship of the two provided integers, reporting that integer ?? is (larger, smaller, same as) integer?? #include int main(void) { int aa, bb; // declare 2 int variables printf("Enter an integer\n"); scanf("%d", &aa); printf("Enter another integer\n"); scanf("%d", &bb); if ( aa == bb ) { printf ("The integers are the same. %d==%d\n", aa,bb); } if ( aa < bb) { printf ("The integer %d is less than %d\n", aa, bb); } if ( aa > bb) { printf ("The integer %d is less than %d\n", bb, aa); } return 0; } 5. What is the output by each of the following printf statements? Explain. int A=12; a) printf("%d \n", 'A'+A ); // ascii value of A (65), is added to the value stored in variable A (12), and the result is printed as a number (77). b) printf("%c\n", 'A' + A); // ascii value of A (65), is added to the value stored in variable A (12), and the result is printed as a character (M). c) printf("%d \n", 'Z' - A); // ascii value of Z (90), is subtracted from the value stored in variable A (12), and the result is printed as a number (78). d) printf("%c \n", 'Z' - A); // ascii value of Z (90), is subtracted from the value stored in variable A (12), and the result is printed as a character (W).