multiplication table in c using array

Multiplication Table in C Using Array

Here is an example of how to create a multiplication table in C using an array:

#include <stdio.h>

#define SIZE 10

int main() {
    int table[SIZE][SIZE];

    // Fill the array with the multiplication values
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            table[i][j] = (i + 1) * (j + 1);
        }
    }

    // Print the multiplication table
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            printf("%4d ", table[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Explanation of each step:

  1. The SIZE constant is defined to represent the size of the multiplication table. In this example, it is set to 10.

  2. An array table of size SIZE by SIZE is declared to store the multiplication values.

  3. Two nested for loops are used to fill the array with the multiplication values. The outer loop iterates over the rows, and the inner loop iterates over the columns. The multiplication value for each cell is calculated as (i + 1) * (j + 1).

  4. Another set of nested for loops is used to print the multiplication table. The outer loop iterates over the rows, and the inner loop iterates over the columns. The printf function is used to print each value in a formatted manner.

  5. The program ends with a return 0; statement, indicating successful execution.

This program will generate a multiplication table from 1 to 10. You can modify the SIZE constant to generate a larger or smaller table.

I hope this helps! Let me know if you have any further questions.