codescracker
c

C Program to Print Table of Number



« Previous Program Next Program »

In this tutorial, you will learn and get code about printing the table in following ways:

C Print Table of a Given Number

To print the table of any number in C programming, you have to ask from user to enter any number. Then multiply the number with 1 to 10 and display the multiplication result at the time of multiplying the number with 1, 2, 3, ...., 9, 10 as shown here in the program given below.

The question is, write a program in C to receive any number from user (at run-time) and print its table. Here is the answer of this question:

#include<stdio.h>
#include<conio.h>
int main()
{
    int num, i, tab;
    printf("Enter the number: ");
    scanf("%d", &num);
    printf("\nTable of %d is:\n", num);
    for(i=1; i<=10; i++)
    {
        tab = num*i;
        printf("%d * %2d = %2d\n", num, i, tab);
    }
    getch();
    return 0;
}

As the program was written under Code::Blocks IDE, therefore after successful build and run, you will get the following output:

c program print table of number

Supply any number say 5 and press ENTER key to see the table of 5 as given in the second snapshot of the sample run:

c print table of any number

Program Explained

C Print Table from 1 to 10

This program will print table from 1 to 10:

#include<stdio.h>
#include<conio.h>
int main()
{
    int num=1, res, i, j;
    printf("\t\tTable from 1 to 10\n\n");
    for(i=0; i<10; i++)
    {
        printf("Table of %d = ", num);
        for(j=1; j<=10; j++)
        {
            res = num*j;
            printf("%d  ", res);
        }
        printf("\n");
        num++;
    }
    getch();
    return 0;
}

Here is its sample run:

c table from 1 to 10

C Print Table in Given Range

Let's create another program that will also print the table of number. But this time, the program will ask to enter the range (starting and ending number). The table of all the numbers that comes in between these two given numbers (including both), will gets printed as output:

#include<stdio.h>
#include<conio.h>
int main()
{
    int n1, n2, i, j;
    printf("Enter the value of n1 (starting point): ");
    scanf("%d", &n1);
    printf("Enter the value of n2 (ending point): ");
    scanf("%d", &n2);
    for(i=n1; i<=n2; i++)
    {
        printf("Table of %d:\n", i);
        for(j=1; j<=10; j++)
        {
            printf("%d x %d = %d\n", i, j, i*j);
        }
        printf("\n");
    }
    getch();
    return 0;
}

Here is the first snapshot of the sample run:

print table between two number c

Now supply any two number say 2 and 3 as starting and ending point and press ENTER to see the output. The output will be the table of 2 and 3:

print table between two number c

Same Program in Other Languages

C Online Test


« Previous Program Next Program »



© Copyright 2021. All Rights Reserved.

CodesCracker