Javatpoint Logo
Javatpoint Logo

Table Program in C

This article will write the table programs using loops (for, do-while, and while loop) and functions (user-defined and recursion function) in the C programming language.

A table (or multiplication table) of numbers is generated by multiplying a constant number with an iterative number from 1 to 10 to get the table. In other words, we can get the table of a number by multiplying the given number with counting from 1, 2, 3, 4, 5, ..., 9, 10. And on each iteration, the value of counting is incremented by 1, which goes up to 10, to print a complete table.

For example, suppose we want to write the table of 5 in C language. So, first, we take 5 as input from the user, and then, we use a loop or function that multiplies the number 5 by 1 (5 * 1), and then (5 * 2), (5 * 3), to the last (5 * 10) number, to get the complete table of the given numbers.

Table Program in C

Different ways to generate the table program

Following are the various ways to generate the table program in the C programming language.

  1. Using for loop
  2. Using while loop
  3. Using do-while loop
  4. Using user-defined function
  5. Using recursion function
  6. Using if and goto statement
  7. Using for loop and pointer
  8. Using nested for loop

Program to generate the table of a given number using for loop

Let's consider an example to print the table of the specific number using for loop in the C programming language.

Program1.c

Output

Enter a number to generate the table in C: 7
 Table of 7
 7 * 1 = 7
 7 * 2 = 14
 7 * 3 = 21
 7 * 4 = 28
 7 * 5 = 35
 7 * 6 = 42
 7 * 7 = 49
 7 * 8 = 56
 7 * 9 = 63
 7 * 10 = 70

In the above code, for loop executes from 1 to 10, the given number is multiplied by 1, and the next iteration is multiplied by 2, and the process continues until it multiplies the number to 10. Finally, it prints the table on the screen.

Program to generate the table of a number using while loop

Let's consider an example to print the table for a number using a while loop in the C programming language.

Program2.c

Output

Enter a number to generate the table in C: 8
 Table of 8
  8 x 1 = 8
 8 x 2 = 16
 8 x 3 = 24
 8 x 4 = 32
 8 x 5 = 40
 8 x 6 = 48
 8 x 7 = 56
 8 x 8 = 64
 8 x 9 = 72
 8 x 10 = 80

Program to generate the table of a number using do-while loop

Let's consider an example to print the number table using a do-while loop in the C programming language.

Program3.c

Output

Enter a number to generate the table in C: 3
 Table of 3
 3 x 1 = 3
 3 x 2 = 6
 3 x 3 = 9
 3 x 4 = 12
 3 x 5 = 15
 3 x 6 = 18
 3 x 7 = 21
 3 x 8 = 24
 3 x 9 = 27
 3 x 10 = 30

Program to generate the table using for loop and user-defined function

Let's consider an example to print the table of the specific number using user-defined function and for loop in the C programming language.

Program4.c

Output

Enter a number to get the table: 23
 The multiplication table of 23
 23 x 1 = 23
 23 x 2 = 46
 23 x 3 = 69
 23 x 4 = 92
 23 x 5 = 115
 23 x 6 = 138
 23 x 7 = 161
 23 x 8 = 184
 23 x 9 = 207
 23 x 10 = 230

Program to generate the table of a number using recursion function

Let's write an example to print the number table using the recursion function in the C programming language.

Program5.c

Output

Enter a number to generate the table in C: 9
 Table of 9
 9 x 1 = 9
 9 x 2 = 18
 9 x 3 = 27
 9 x 4 = 36
 9 x 5 = 45
 9 x 6 = 54
 9 x 7 = 63
 9 x 8 = 72
 9 x 9 = 81
 9 x 10 = 90

Program to generate the table of a number using goto statement

Let's consider an example to print the number table using a goto statement in the C programming language.

Program6.c

Output

Enter a number to get the table: 5
 5 * 1 = 5
 5 * 2 = 10
 5 * 3 = 15
 5 * 4 = 20
 5 * 5 = 25
 5 * 6 = 30
 5 * 7 = 35
 5 * 8 = 40
 5 * 9 = 45
 5 * 10 = 50

Program to generate the table of a number using pointer

Let's consider an example to print the number table using a pointer in the C programming language.

Program7.c

Output

Enter a number to print the table: 17
 Table of 17:
 17 * 1 = 17
 17 * 2 = 34
 17 * 3 = 51
 17 * 4 = 68
 17 * 5 = 85
 17 * 6 = 102
 17 * 7 = 119
 17 * 8 = 136
 17 * 9 = 153
 17 * 10 = 170

Program to generate the table from 2 to 10 using nested for loop

Let's consider an example to print the table from 2 to 10 using nested for loop in the C programming language.

Program8.c

Output

Enter the first number from to get the table: 2
 Enter the last number: 10
 Table of 2 =>  |   2 | |   4 | |   6 | |   8 | |  10 | |  12 | |  14 | |  16 | |  18 | |  20 |
 Table of 3 =>  |   3 | |   6 | |   9 | |  12 | |  15 | |  18 | |  21 | |  24 | |  27 | |  30 |
 Table of 4 =>  |   4 | |   8 | |  12 | |  16 | |  20 | |  24 | |  28 | |  32 | |  36 | |  40 |
 Table of 5 =>  |   5 | |  10 | |  15 | |  20 | |  25 | |  30 | |  35 | |  40 | |  45 | |  50 |
 Table of 6 =>  |   6 | |  12 | |  18 | |  24 | |  30 | |  36 | |  42 | |  48 | |  54 | |  60 |
 Table of 7 =>  |   7 | |  14 | |  21 | |  28 | |  35 | |  42 | |  49 | |  56 | |  63 | |  70 |
 Table of 8 =>  |   8 | |  16 | |  24 | |  32 | |  40 | |  48 | |  56 | |  64 | |  72 | |  80 |
 Table of 9 =>  |   9 | |  18 | |  27 | |  36 | |  45 | |  54 | |  63 | |  72 | |  81 | |  90 |
 Table of 10 =>  |  10 | |  20 | |  30 | |  40 | |  50 | |  60 | |  70 | |  80 | |  90 | | 100 |






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA