C Programming

Practise Exercise 3: printf() and scanf()

1. The statement which prints out the value of the integer variable sum, is

printf("%s", sum);
print("%i", sum);
printf("%d", sum);
printf("%d", &sum);

2. The statement which prints out the text string "Welcome", followed by a newline, is.

printf("Welcome\n");
printf(Welcome, '\n');
printf(Welcome\n);
printf('Welcome', '\n');

3. The statement which prints out the value of the character variable letter, is

printf(letter);
printf("%c", &letter);
printf("%d", letter);
printf("%c", letter);

4. The statement which prints out the value of the float variable discount, is

printf("%s", discount);
print('discount');
printf("%f", discount);
printf("%d", discount);

5. The statement which prints out the value of the float variable dump using two decimal places, is

printf("%f", dump);
printf("%.2f", dump);
printf("%2f", dump);
printf("%f", &dump);

6. The statement to read a decimal value from the keyboard, into the integer variable sum, is

scanf("%d", &sum);
scanf(sum);
scanf("%s", sum);
scanf("%f", &sum);

7. The statement to read a float value into the variable discount_rate is

scanf("%f", discount_rate);
scanf("%d", &discount_rate);
scanf(discount_rate);
scanf("%f", &discount_rate);

8. The statement to read a single character from the keyboard into the variable operator, skipping leading blanks, tabs and newline characters, is

scanf("%s", operator);
scanf("%c", &operator);
scanf(" %c", &operator);
scanf("%c", operator);


©Copyright B Brown. 1984-1999. All rights reserved.