Recap Challenge #2
Part of the Fundamentals section of Coddy's C journey — lesson 45 of 63.
Challenge
EasyCreate a program that prints a multiplication table for values from 1 to n (where n is provided by the user).
Your program should print a multiplication table from 1 to n using nested loops
The table should be formatted with each row showing the products of multiplying a number by all values from 1 to n.
If n = 4, the output should look exactly like this:
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16Use the format specifier %2d followed by a space for each number. This reserves two character spaces for each product.
Example for %2d :
Single digit (pushed to the right):
printf("%2d ", 5); // Output: " 5 "Double digit (fills both slots):
printf("%2d ", 10); // Output: "10 "Try it yourself
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
// Create nested loops to print the multiplication table
return 0;
}All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge6Loops
For LoopWhile LoopDo While LoopBreakContinueRecap Challenge #1Nested LoopsInfinite LoopsRecap Challenge #2