Put your answers in a file called StudentNumber_StudentName_ASD1_Homework02.txt. For example, if your student number is 242438187709 and your name is Mohammed Ali, your file name should be 242438187709_MohammedAli_ASD1_Homework01.txt.
Consider the following C program.
#include <stdio.h>
void main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("You have entered %d.\n", num);
}
What does the program do?
Run the program. When prompted, give the program, the input 4 and hit enter. Does the program behave correctly?
Run again the program. When prompted, give the program, the input 4 2 (4, then space, then 2) and hit enter. What do you notice?
Consider the following C program.
#include <stdio.h>
void main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("You have entered %d.\n", num);
printf("Enter another integer: ");
scanf("%d", &num);
printf("You have entered %d.\n", num);
}
What does the program do?
Run the program. When prompted, give the program, the input 4 and hit enter. When prompted again, give the program the number 2. Does the program behave correctly?
Run again the program. When prompted, give the program, the input 4 2 (4, then space, then 2) and hit enter. What do you notice?
Consider the following C program.
#include <stdio.h>
void main()
{
int num1, num2, num3;
printf("Enter an integer: ");
scanf("%d", &num1);
printf("You have entered %d.\n", num1);
printf("Enter another integer: ");
scanf("%d", &num2);
printf("You have entered %d.\n", num2);
printf("Enter another integer: ");
scanf("%d", &num3);
printf("You have entered %d.\n", num3);
printf("You have input the numbers %d, %d, and %d.\n", num1, num2, num3);
}
What does the program do?
Run the program. When prompted, give the program, the input 4 and hit enter. When prompted again, give the program the number 2. When prompted again, give the program the number 1. Does the program behave correctly?
Run again the program. When prompted, give the program, the input 4 2 (4, then space, then 2) and hit enter. What do you notice?
Based on your observations before, what can you conclude about scanf()?