Write a program to print the table of the given number.
Example 1:
Input: num=5
Output: 5 10 15 20 25 30 35 40 45 50
Approach:
Java
public class PrintTable {public static void main(String[] args) {int num = 5;printTable(num);}private static void printTable(int num) {for (int i = 1; i <= 10; i++) {System.out.println(num + "*" + i + " = " + i * num);}}}
C++
#include <bits/stdc++.h>using namespace std;//function which print//table of given numbervoid printTable(int n){for(int i=1;i<=10;i++)cout<<i*n<<" ";}int main(){int num=5;cout<<"Table is\n";printTable(num);return 0;}
No comments:
Post a Comment