Multiplication Table|Coding Problems

Akash Kumar
1 min readAug 3, 2021

--

Problem Statement:

Print the multiplication table of a given number N.

Example 1:

Input:
N = 9
Output:
9 18 27 36 45 54 63 72 81 90
Explanation:
The table of 9 is the output whose 1st
term is 9 and the 10th term is 90.

Example 2:

Input:
N = 2
Output:
2 4 6 8 10 12 14 16 18 20

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1 <= N <= 106

Code & Algorithm:

/* author : @akash */
/*
problem is:-
*/#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define ld long double
void solve()
{
int n;
cin>>n;
for(int i=1;i<=10;++i)
{
cout<<n*i<<" ";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
cout<<"\n";
}
return 0;
}
// time complexity of this algorithm is : T(n)=O(1)

Output:

Input:Test Case=1
N = 2

Output:
2 4 6 8 10 12 14 16 18 20

Thank You.

Akash Kumar

Software Engineer

--

--