Program to print multiplication table of n up to m using While loop
- Write a program to print multiplication table of n up to m using While loop in C
- Write a program to print multiplication table of n up to m using While loop in C++
- Write a program to print multiplication table of n up to m using While loop in Python
- Write a program to print multiplication table of n up to m using While loop in PHP
- Write a program to print multiplication table of n up to m using While loop in Java
- Write a program to print multiplication table of n up to m using While loop in Java Script
- Write a program to print multiplication table of n up to m using While loop in C#
Explanation:
Using a for loop, you multiply n by each integer from 1 to m and display the result to print the multiplication table of a number n up to m.
Logic
- Take inputs for n (the number for which the table is to be printed) and m (the limit up to which the table is printed).
- Use a for lop to iterate from 1 to m.
- In each iteration, calculate n × i and display the result.
Program to print multiplication table of n up to m using While loop
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h>
int main() {
int n, m, i = 1;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("Enter the value of m: ");
scanf("%d", &m);
while (i <= m) {
printf("%d * %d = %d\n", n, i, n * i);
i++;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n, m, i = 1;
cout << "Enter the value of n: ";
cin >> n;
cout << "Enter the value of m: ";
cin >> m;
while (i <= m) {
cout << n << " * " << i << " = " << n * i << endl;
i++;
}
return 0;
}
n = int(input("Enter the value of n: "))
m = int(input("Enter the value of m: "))
i = 1
while i <= m:
print(f"{n} * {i} = {n * i}")
i += 1
<?php
$n = (int)readline("Enter the value of n: ");
$m = (int)readline("Enter the value of m: ");
$i = 1;
while ($i <= $m) {
echo "$n * $i = " . ($n * $i) . "\n";
$i++;
}
?>
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
System.out.print("Enter the value of m: ");
int m = sc.nextInt();
int i = 1;
while (i <= m) {
System.out.println(n + " * " + i + " = " + (n * i));
i++;
}
sc.close();
}
}
let n = parseInt(prompt("Enter the value of n: "));
let m = parseInt(prompt("Enter the value of m: "));
let i = 1;
while (i <= m) {
console.log(`${n} * ${i} = ${n * i}`);
i++;
}
using System;
class Program {
static void Main() {
Console.Write("Enter the value of n: ");
int n = int.Parse(Console.ReadLine());
Console.Write("Enter the value of m: ");
int m = int.Parse(Console.ReadLine());
int i = 1;
while (i <= m) {
Console.WriteLine($"{n} * {i} = {n * i}");
i++;
}
}
}