Object

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

Algorithm

  1. Declare integer variables num and i.
  2. Read num.
  3. Repeat FOR i = 1 to 10 by 1
    • Write num*i.
    • [End of FOR loop.]
  4. Exit.

Flowchart

C++ Source Code

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

int main()
{
  int num;
  cout << "Enter any number: ";
  cin >> num;

  for (int i = 1; i <= 10; i++)
  {
    cout << "\n" << num << " * " << i << " = " << num * i;
  }
  return 0;
}

C Source Code

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

int main()
{
  int num, i;
  printf("Enter any number: ");
  scanf("%d", &num);
  for(i=1; i<=10; i++)
     printf("\n%d * %d = %d", num, i, num*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