C Programming

Answers: Practise Exercise 3: printf() and scanf()

1. Use a printf statement to print out the value of the integer variable sum


	printf("%d", sum);

2. Use a printf statement to print out the text string "Welcome", followed by a newline.


	printf("Welcome\n");

3. Use a printf statement to print out the character variable letter


	printf("%c", letter);

4. Use a printf statement to print out the float variable discount


	printf("%f", discount);

5. Use a printf statement to print out the float variable dump using two decimal places


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

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


	scanf("%d", &sum);

7. Use a scanf statement to read a float variable into the variable discount_rate


	scanf("%f", &discount_rate);

8. Use a scanf statement to read a single character from the keyboard into the variable operator. Skip leading blanks, tabs and newline characters.


	scanf(" %c", &operator);


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