- On
- By
- 0 Comment
- Categories: for loop, multiply, nested for
C Program to multiplication table using Array
C Program to multiplication table using Array
In this tutorial , we will discuss about C Program to multiplication table using Array
We can display multiplication in C language of various way. In this tutrorial ,we will learn how to display multiplication table using array in C language
Here, we can print 12 * 12 multiplication table using array with for loop
C code to multiplication table using Array- #1
Program 1
// C Program to multiplication table using Array #include <stdio.h> int main() { int num,i; int table[10]; // Array to store multiplication result; printf("Enter a number as you wish:"); //input a number to generates multiplication table scanf("%d",&num); //Store the multiplication table in the array for(i=0; i<10; i++){ table[i]=num*(i+1); } //Display the multiplication table printf("Multiplication table of %d\n",num); for(i=0; i<10; i++){ printf("%d * %d =%d\n",num,i+1,table[i]); } return 0; }
When the above code is executed, it produces the following result
Enter a number as you wish:12
Multiplication table of 12
12 * 1 =12
12 * 2 =24
12 * 3 =36
12 * 4 =48
12 * 5 =60
12 * 6 =72
12 * 7 =84
12 * 8 =96
12 * 9 =108
12 * 10 =120
Explanation
The program asks the user for a number
it uses an array to store the results of multiplying the number by integer from 1 to 10
A for loop calculates and stores these results in the array
Another for loop displays the results stored in the array in a formatted manner
C code to multiplication table using Array -#2
Program 2
// C Program to multiplication table using Array #include <stdio.h> int main() { int num,i; int table[10][2]; // Array to store multiplication value; printf("Enter a number as you wish:"); //Asking user for a number //reading the number to generates multiplication table scanf("%d",&num); //Storing the multiplication factors and results in the array for(i=0; i<10; i++){ table[i][0]=(i+1);//multipliers(1 to 10) table[i][1]=num *(i+1);//results } //Displaying the multiplication table printf("Multiplication table of %d\n",num); printf("...............................\n"); printf("| Multiplier | Results | \n"); printf("...............................\n"); for(i=0; i<10; i++){ printf("| %2d | %4d |\n",table[i][0], table[i][1]); } return 0; }
When the above code is executed, it produces the following result
Enter a number as you wish:12
Multiplication table of 12
………………………….
| Multiplier | Results |
………………………….
| 1 | 12 |
| 2 | 24 |
| 3 | 36 |
| 4 | 48 |
| 5 | 60 |
| 6 | 72 |
| 7 | 84 |
| 8 | 96 |
| 9 | 108 |
| 10 | 120 |
Suggested for you
Two dimension array in Java language
Nested for loop in Java language
Nested while loop in Java language
Java program to print multiplication table
C program to print multiplication table
C++ program to print multiplication table
Python program to print multiplication table
Java program to print multiplication table using array
C program to print multiplication table using array