Today, you will create a program that generates a multiplication table for a number provided by the user. This exercise is a great way to practice working with loops and understand how to perform repetitive tasks programmatically.
For example, if the user inputs 5, the program should display:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
By solving this challenge, you will:
Each line should follow this format:
<number> x <multiplier> = <product>
# Get input from the user
number = int(input("Enter a number to generate its multiplication table: "))
# Generate multiplication table from 1 to 10
print(f"Multiplication Table for {number}:")
for i in range(1, 11):
print(f"{number} x {i} = {number * i}")
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get input from the user
System.out.print("Enter a number to generate its multiplication table: ");
int number = scanner.nextInt();
// Generate multiplication table from 1 to 10
System.out.println("Multiplication Table for " + number + ":");
for (int i = 1; i <= 10; i++) {
System.out.println(number + " x " + i + " = " + (number * i));
}
}
}
// Get input from the user
let number = parseInt(prompt("Enter a number to generate its multiplication table:"));
// Generate multiplication table from 1 to 10
console.log(`Multiplication Table for ${number}:`);
for (let i = 1; i <= 10; i++) {
console.log(`${number} x ${i} = ${number * i}`);
}
In Day 14: Find the Largest Number, you’ll write a program that finds the largest number from a list of numbers provided by the user.