CodeSolved

A comprehensive source of programming questions and exercises

Building a multiplication table 2

Practice Easy 985/ Download 1218 Views

Write a program that prints the multiplication table as shown below:


1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 22 24 27 30
4 8 12 16 16 24 28 28 32 36 40
5 10 15 20 20 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 14 28 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90100

10 Answers

for i in range(1,11):
    for j in range(1,11):
        print(f'{i*j:<5}',end='')
    print()
n = int(input())
for i in range(1,n + 1):
    for j in range(1,n + 1):
        print(i*j, end =" ")
    print()

Numbers are not tidy and must be arranged through F-Stroving Alvandsina


num = 10
for i in range(1,num+1):
    for j in range(1,num+1):
        print(f"{i * j:5}",end="")
    else:
        print("\n")

In sorting results with F-Stroving it is best to align the results from one side and also do not require the Else section and also write n \ inside print because blank creates a new line Alvandsina


Thank you for the comment you gave Arman.danyy


num = int(input('Number: '))
a = num**2
for i in range(1,num+1):
    for j in range(1,num+1):
        print(i*j,end=' '*(1+len(str(a)) - len(str(j*i))))
    print()
User 22 Download Python
size = 10
for i in range(1, size + 1):
    row = ""
    for j in range(1, size + 1):
        row += str(i * j).ljust(4)
    print(row)
Roghaye.m Download Python
num1 = int(input('Number1:'))
num2 = int(input('Number2:'))
for i in range(1,num1+1):
    for j in range(1,num2+1):
        print(f'{i*j:<4}',end='')
    print()
Alvandsina Download Python
for i in range(1:11):
for j in range(1:11):
print(f{i*j}:<5, end="")
User 1496 Download Python
package Tax.App.cmd;
public class Jadval_Zarb2 {
    public static void main(String[] args) {
        for (int i = 1; i < 11; i++) {

            for (int j = 1; j < 11; j++) {
                if (i * j > 9) System.out.print(i * j + "  ");
                else System.out.print(i * j + "   ");
            }
            print(3);
        }
    }

    public static void print(int x) {
        for (int i = 0; i < x; i++) {
            System.out.println();
        }
    }
}
Tahabx3 Download Java
package opp;
public class swit {
	public static void main(String[] args) {
		for(int i = 0 ; i < 10;i++) {
			for(int j = 0 ;j<10;j++) {
				System.out.print((i+1)*(j+1) + "  ");
			}
			System.out.print("\n");
		}
	}
}
Makcode Download Java
def print_multiplication_table():
    # Printing of the table
    for i in range(1, 11):
        print(f"{i:2}", end=" ")  # Print numbers 1 to 10 with distance
    print()  # Going to the next line

    # Multiplication table printing
    for i in range(1, 11):
        for j in range(1, 11):
            print(f"{i * j:2}", end=" ")  # The calculation and printing of the multiplication
        print()  # Go to the next line after each row

# Implementation of the function
print_multiplication_table()
Mma123 Download Python

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close