CMSC 104

Example problems with printf


Problems:

1) What, if anything, prints when each of the following statements is performed? If nothing prints, then answer "nothing." Assume x = 2 and y = 3.

a.) printf("%d", x);

b.) printf("%d", x + x);

c.) printf("x=");

d.) printf("x=%d", x);

e.) printf("x=%d", x + y, y + y);

f.) z = x + y;

g.) /* printf("x + y = %d", x + y); */

h.) printf("\n");

i.) printf("Welcome "); printf("to Italy! \n");

j.) printf("Welcome \n to Italy! \n");

k.) printf("*\n**\n***\n****\n*****\n");


2.) Write a single C statement that prints the message " Enter two Numbers." This statement should print the double quotes to the screen.
3.) Identify and correct the errors in each of the following statements. There may be more than one error.

a.) printf("The product of %d and %d is %d"\n, x, y);

b.) printf("Remainder of %d divided by %d is\n", x, y, x % y);

c.) print("The sum is %d\n," x + y);

d.) Printf("The value you entered is: %d\n, &value);