Computer Science, asked by krishviradiya29, 3 months ago

Write a program to accept a number and prints multiplication table for n times. n must be

taken from user.

Sample Input:

n=5 number=3

Sample Output:

3*1=3

3*2=6

3*3=9

3*4=12

3*5=15​


anindyaadhikari13: Please mention the programming language.

Answers

Answered by anindyaadhikari13
4

Required Answer:-

Question:

  • Write a program to accept a number and print it's multiplication table upto n.

Solution:

Here is the program. This is written in Java.

import java.util.*;

public class Table {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number: ");

int a=sc.nextInt();

System.out.print("Enter n: ");

int n=sc.nextInt();

System.out.println("\nHere is the table.");

for(int i=1;i<=n;i++) {

System.out.println(a+" x "+i+" = "+a*i);

}

sc.close();

}

}

Explanation:

  • We will ask the user to enter the number and limit. Then, we will iterate a loop n times (upto limit). Then, we will multiply the loop variable with the number. The result obtained will be displayed on the screen.

Output is attached.

Attachments:

krishviradiya29: thanks
anindyaadhikari13: Do you need in any other language?
Similar questions