Why is input important for a program?
Think about how a program knows what data to use.
Input is how a program gets data from the user or other places. Without input, the program would not know what to process.
What is the main reason programs produce output?
Think about how a program communicates results.
Output is how a program shares the results or information after working with input data. It helps users see what the program did.
Look at the code below. What will it print?
#include <stdio.h> int main() { int number; printf("Enter a number: "); scanf("%d", &number); printf("You entered: %d\n", number); return 0; }
Remember that printf prints text immediately, and scanf waits for input.
The program first prints "Enter a number: ", then waits for the user to type a number. After input, it prints "You entered: " followed by the number. So the full output includes the prompt and the result.
Consider this code snippet. What will happen if the user does not enter any number?
#include <stdio.h> int main() { int x; scanf("%d", &x); printf("Value: %d\n", x); return 0; }
Think about how scanf behaves when no input is given.
scanf waits for the user to enter a valid integer. If no input is given, the program will wait indefinitely until input is provided.
Why must interactive programs have both input and output?
Think about how a conversation works between a user and a program.
Interactive programs need input to receive commands or data from users, and output to show results or feedback. This two-way communication is what makes interaction possible.