THE SYLLABUS QUESTION
What you need to solve
Write a program that prints a multiplication table for a given number and the number of rows in the table. For example, for a number 5 and rows = 3, the output should be: 5 x 1 = 5; 5 x 2 = 10; 5 x 3 = 15.
An integer number (-1,000,000 to 1,000,000), then the row count (1 to 1000).
UNDERSTAND THE IDEA
Explanation
The multiplier starts at 1 and increases until the requested row count. Each iteration prints number × multiplier.
The row count is an input, so the solution does not assume that every table has ten rows.
PLAN BEFORE CODING
Algorithm
- Read the number and row count.
- Reject a row count outside 1–1000.
- Loop from 1 through the requested number of rows.
- Print one formatted multiplication per iteration.
SEE THE CONTROL FLOW
Flowchart
Follow the arrows from Start. Diamonds ask a question; labeled arrows show the answer. A returning arrow repeats a loop. Function internals are grouped where needed; later input checks follow the rules in the program.
On a phone, scroll sideways to read the diagram at full size. Open full-size flowchart ↗
#include <stdio.h>
int main(void) {
long long number;
int rows;
if (scanf("%lld %d", &number, &rows) != 2 ||
number < -1000000 || number > 1000000 || rows < 1 || rows > 1000) {
puts("Invalid input.");
return 1;
}
for (int i = 1; i <= rows; ++i)
printf("%lld x %d = %lld\n", number, i, number * i);
return 0;
}
Code loads into the existing compiler. Enter the sample input there; sign-in and execution rules stay the same.
Compile and run locally
gcc -std=c17 multiplication-table.c -o lab
./labOn Windows, run .\lab.exe after compiling with GCC. The interest program requires the math library where applicable.
FOLLOW THE VALUES
Dry run
| Step / state | Operation | Result |
|---|---|---|
| i = 1 | 5 × 1 | 5 |
| i = 2 | 5 × 2 | 10 |
| i = 3 | 5 × 3 | 15 |
CHECK THE BEHAVIOR
Sample input & output
Each output below was produced by compiling and running this exact program. Input values are entered in the stated order; the examples do not print input prompts.
Sample 1
5 3
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
Sample 2
-2 4
-2 x 1 = -2
-2 x 2 = -4
-2 x 3 = -6
-2 x 4 = -8
Sample 3
0 1
0 x 1 = 0
Common mistakes
- Use i <= rows to include the final row.
- Do not replace the entered row count with a fixed constant such as 10.
WHY THIS GROWTH RATE?
Time and space complexity
Time O(rows); auxiliary space O(1).
Let r be the requested number of rows. The loop runs exactly r times. Every iteration multiplies two fixed-width integers and prints one row.
The work is proportional to r: T(r) = c × r + k, so time is O(r). Doubling the row count approximately doubles the work. Only the number, counter and row limit are stored, giving O(1) auxiliary space.
Big-O describes how work grows as the stated input quantity grows; fixed factors and lower-order terms are omitted. The analysis treats fixed-width arithmetic as constant cost and the published limits as practical safety bounds.