Loops
Read three inputs in sequence and print a chosen range of multiplication facts.
Complete program
#include <stdio.h>
int main(void) {
int number, start, end;
printf("Number: ");
if (scanf("%d", &number) != 1) return 1;
printf("Start: ");
if (scanf("%d", &start) != 1) return 1;
printf("End: ");
if (scanf("%d", &end) != 1) return 1;
if (number < -1000 || number > 1000 || start < 0 || end > 100 || start > end) return 1;
for (int i = start; i <= end; ++i)
printf("%d x %d = %d\n", number, i, number * i);
return 0;
}
Opens a new program without replacing your saved code. Press Run when you are ready.
How it works
Three separate scanf calls show real interactive input. Type each response after its prompt and press Enter. Focus remains in the terminal between requests.
The inclusive end condition prints the last requested row. The validation prevents a reversed range, unbounded output, or large products. To make the interval exclusive, change <= to < and compare the last row.
Sample input
5
1
3Enter these values when prompted. The transcript below includes typed responses.
Expected output
Number: 5
Start: 1
End: 3
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15Concepts to practice
- Sequential stdin
- Inclusive ranges
- Formatted output
Predict a different input or change one value, then compare the result with your prediction. Keep changes within the documented bounds and read warnings before trusting an answer.