PRINTING TABLE

Question - 1

      Write a program to print the table of N in the following manner.
             N * 1=N
             N * 2=2N
             N * 3=3N
             N * 4=4N
             ….…….....
             ….…….....
             N * 10=10N

INPUT:-
    1. A single line taking input N from the user.
        
OUTPUT:-

          The table in a manner given above.   

Ans

         The approach to code the question is very easy. We have to concentrate on three things mainly while using any loop.
  1. The starting and ending limit of the loop,
  2. The change in increment size with each iteration and
  3. Small calculation part.
Here the starting limit is 1 and ending limit is 10.
The change in increment size is 1 in each iteration because we are multiplying N with 1,2,3.... up to 10.
And the small calculation part is nothing but a simple output and a simple multiplication as follows.
So you have pseudocode:-
  • Taking input from the user -> N.
  • Using a loop with starting and ending limit as discussed above and the proper increment operator.
  • Inside the loop, we have a small calculation that going to iterate as many time as the condition of the loop remains true. Here we have to set a condition that makes the loop run 10 times.
  • And we are done :)

C++ Approach :- 

#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N; /// taking input from the user
    for(int i=1;i<=10;i++) ///i<=10 is the condition, i++ is the increment
    {
        cout << N << " * " << i << " = " << N*i << endl; /// small calculation part
    }
    return 0;
}

Python Approach : -

N=int(input())
for i in range(1,11):
    print(N,"*",i,"=",N*i)

Hope that helps, Keep Coding :).

Comments