In: Computer Science
This program is for C.
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
#include
#include
#include
int main()
{
srand(time(NULL));
int i,j;
int A[3][3],B[3][3],C[3][3];
for(i=0;i<3;i++){
for(j=0;j<3;j++){
int r1 = ( rand() % 10 );
int r2 = -(( rand() % 10 ));
A[i][j]=r1;
B[i][j]=r2;
C[i][j]=A[i][j]+B[i][j];
printf("\n%d + %d = %d",A[i][j],B[i][j],C[i][j]);
}
}
return 0;
}