Answer 01

  1. The program prompts the user to enter an integer, reads the integer, then prints it back to the user.

  2. The program behaves correctly: it asks for a number, reads it, and outputs it.

  3. We notice that scanf() reads the first number, and ignores the rest.

Answer 02

  1. The program prompts the user to enter an integer, reads the integer, then prints it back to the user. The program then, repeats the same procedure.

  2. The program behaves correctly: it asks for a number, reads it, and outputs it; then does it again.

  3. We notice that scanf() reads the first number, outputs it, then outputs the second number. It does not ask the user for another number.

Answer 03

  1. The program prompts the user to enter an integer, reads the integer, then prints it back to the user. The program then, repeats the same procedure two times. Finally, the program prints all the entered values.

  2. The program behaves correctly: it asks for a number, reads it, and outputs it; then does it again two times.

  3. We notice that scanf() reads the first number, outputs it, then outputs the second number. It then asks the user for the third number.

Answer 04

The function scanf() will first read any unprocessed input, and will prompt the user only when the unprocessed input is finished.

Last modified: Tuesday, 5 November 2024, 10:40 PM