# C Program on two-dimensional array initialized at run time

## Problem

Calculate the sum and product of all elements in an array by using the run-time compilation.

## Solution

A two-dimensional array is used in situations where a table of values have to be stored (or) in matrices applications

The syntax is as follows −

datatype array_ name [rowsize] [column size];

For example, int a ;

Number of elements in array = rowsize *columnsize = 5*5 = 25

## Example

Following is the C program to calculate the sum and product of all elements in an array by using the run-time compilation −

Live Demo

#include<stdio.h>
void main(){
//Declaring the array - run time//
int A,B,i,j,sum[i][j],product[i][j];
//Reading elements into the array's A and B using for loop//
printf("Enter elements into the array A: ");
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("A[%d][%d] :",i,j);
scanf("%d",&A[i][j]);
}
printf("");
}
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("B[%d][%d] :",i,j);
scanf("%d",&B[i][j]);
}
printf("");
}
//Calculating sum and printing output//
printf("Sum array is : ");
for(i=0;i<2;i++){
for(j=0;j<3;j++){
sum[i][j]=A[i][j]+B[i][j];
printf("%d\t",sum[i][j]);
}
printf("");
}
//Calculating product and printing output//
printf("Product array is : ");
for(i=0;i<2;i++){
for(j=0;j<3;j++){
product[i][j]=A[i][j]*B[i][j];
printf("%d\t",product[i][j]);
}
printf("");
}
}

## Output

When the above program is executed, it produces the following result −

Enter elements into the array A:
A :12
A :23
A :03

A :25
A :34
A :01

B :03
B :46
B :23

B :01
B :24
B :32

Sum array is:
15    69    26
26    58    33
Product array is:
36    1058   69
25    816    32