Object

Write a program to print the table of a given number.

Algorithm

  1. Declare integer variables num and i.
  2. Read num.
  3. Set i = 1.
  4. Repeat WHILE i <= 10
    • Write num*i.
    • i++.
    • [End of WHILE loop.]
  5. Exit.

Flowchart

C++ Source Code

// program 53
#include<iostream>
using namespace std;

int main()
{
  int num, i;
  cout << "Enter any number: ";
  cin >> num;
  i = 1;
   
  while (i <= 10)
  {
    cout << "\n" << num << " * " << i << " = " << num * i;
    i++;
  }
  return 0;
}

C Source Code

/*program 53*/
#include<stdio.h>

int main()
{
  int num, i;
  printf("Enter any number: ");
  scanf("%d", &num);
  i = 1;
  while(i<=10)
     {
     printf("\n%d * %d = %d", num, i, num*i);
     i++;
     }
  return 0;
}

Output

Enter any number: 8

8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80

Design a site like this with WordPress.com
Get started