In: Computer Science
-1 -2 -3 -4 -5
-6
-11
-16
You are required to write a C program to perform two tasks.
A[i][j] = A[i-1][j]*A[i][j-1] for i > 0 and for j > 0.
After all elements in the 4x5 2-D array are fully specified, print out the content of the entire 4x5 2-D array according to the format shown below.
Well i have tried to explain each and everything in the code itself . But if you still dont get anything than ask in comment section please.
CODE :
#include <stdio.h>
#define row 4
#define col 5
int main() {
// as size of row and coloumns are predefined
// here long long is taken as multiplication can overflow
long long int A[row][col];
// putting te known values in A[][]
// initialsed first row first
for(int i=0;i<col;i++){
A[0][i]=-(i+1);
}
// now first col is initialsed
for(int i=0;i<row;i++){
A[i][0]=-(5*i+1);
}
// now the main part begins as we have already filled 1st row
and 1 st col
// now we will traverse full 2d array starting from 1,1 to 3,4
for(int i=1;i<row;i++){
for(int j=1;j<col;j++){
A[i][j]=A[i-1][j]*A[i][j-1];
}
}
// finally printing arrary
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
printf("%lld ",A[i][j]);
}
printf("\n");
}
return 0;
}
OUTPUT :