xxxxxxxxxx
enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
8 8 8
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18
xxxxxxxxxx
double[][] c = new double[N][N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = 0; k < N; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
xxxxxxxxxx
#include <stdio.h>
int main()
{
int namta[11][10]; //programme will run upto 11 multiplication tables, each table has 10 columns
int i,j;
for(i = 1; i <= 11; i++)
{
for(j = 1; j <= 10; j++)
{
namta[i][j] = i * j; //getting the multiplating value into the array
}
}
for(i = 1; i <= 10; i++){
for(j = 1; j <= 10; j++){
printf("%d x %d = %d\n",i,j,namta[i][j]); //printing the array of results calculated in the previous loops
}
printf("\n");
}
return 0;
}
xxxxxxxxxx
#include <stdio.h>
int main()
{ int a_rows,a_cols,b_rows,b_cols,i,j,k,sum=0;
printf("Enter the rows and columns for first matrix (row)(col) :\n");
scanf("%d %d",&a_rows,&a_cols);
printf("Enter the rows and columns for second matrix (row)(col) :\n");
scanf("%d %d",&b_rows,&b_cols);
int a[a_rows][a_cols], b[b_rows][b_cols],matrix[10][10];
if(a_cols != b_rows){
printf("Sorry! We can't multiply the matrix because the column number of matrix 1 and the row number of matrix 2 aren't same !!\n");
}else{
printf("Enter elements for first matrix :\n");
for(i = 0; i < a_rows; i++){
for(j = 0; j< a_cols; j++){
scanf("%d",&a[i][j]);
}
}
printf("Enter elements for second matrix :\n");
for(i = 0; i < b_rows; i++){
for(j = 0; j < b_cols; j++){
scanf("%d",&b[i][j]);
}
}
printf("multiplying matrix....\n");
//multiplying matrix
for(i=0; i < a_rows; i++){
for(j = 0; j < b_cols; j++){
for(k = 0; k < a_cols; k++){
sum+=a[i][k] * b[k][j];
}
matrix[i][j] = sum;
sum=0;
}
printf("\n");
}
printf("first matrix :\n");
for(i = 0; i < a_rows; i++){
for(j = 0; j< a_cols; j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n\n");
printf("second matrix :\n");
for(i = 0; i < b_rows; i++){
for(j = 0; j< b_cols; j++){
printf("%d ",b[i][j]);
}
printf("\n");
}
printf("Multiplied matrix :\n");
for(i = 0; i < a_rows; i++){
for(j = 0; j< b_cols; j++){
printf("%d ",matrix[i][j]);
}
printf("\n");
}
}
return 0;
}