Code:
/*Variety of Program for Matrices*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
struct matrix{ //Reference of function for the Matrices
double** pElements[10][10]; //Pointer for the elements of Matrices
int MRow;
int NColumn;
}val[10];
int rowcol(int &row, int &col, int &x){//Asks for the values of Row and Column
printf("\n\nEnter value for row: ");
scanf("%d",&row);
printf("Enter value for col: ");
scanf("%d",&col);
val[x].MRow=row; //Stores assigned values of Row and Columns
val[x].NColumn=col;
}
int matrixone(int &x){//Asking for values for elements of matrix
int row,col,i,j;
printf("\n\nMATRIX %d: ",x);
rowcol(row,col,x);
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
printf("Enter value for row [%d] and col [%d]: ",i,j);
scanf("%d",&val[x].pElements[i][j]);//Stores elements of matrix
}
}
}
int print(int &x){//Printing of the matrix elements
int row,col,i,j;
printf("\nMatrix %d is: \n",x);
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
printf("%d ",val[x].pElements[i][j]);
}
printf("\n");
}
}
int adding(int &x){ <------------------------NEED HELP HERE!!!!!!!!!!!!!!!
int row,col,i,j;
if(val[1].MRow==val[2].MRow&val[1].NColumn==val[2].NColumn){
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
**val[3].pElements[i][j] = **val[1].pElements[i][j] + **val[2].pElements[i][j];
}
}
}//end of If Statement
else
printf("\nRows/Columns for 2 matrices are not equal! \n");
}
int subtract(int &x){
int row,col,i,j;
if(val[1].MRow==val[2].MRow&val[1].NColumn==val[2].NColumn){
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
// val[3].pElements[i][j] = val[1].pElements[i][j] - val[2].pElements[i][j];
}
}
}//end of If Statement
else
printf("\nRows/Columns for 2 matrices are not equal! \n");
}
int mult(int &x){
int row,col,i,j;
if(val[1].NColumn==val[2].MRow){
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
// val[3].pElements[i][j] = val[1].pElements[i][j] - val[2].pElements[i][j];
}
}
}//end of If Statement
else
printf("\nColumn of Matrix is not equal to Row of Matrix 2!\n");
}
int summate(int &x){
int row,col,i,j=1,inc=0;
do{
for(i=1;i<=row;i++){
//val[x].pElements[i][j+inc] = val[x].pElements[i][j+inc] + val[x].pElements[i][j];
}
inc++;
}while((j+inc)<=col);
}
int transpose(int &x){
int row,col,i,j,temp;
for(i=1;i<=row;i++){
for(j=1;j<=col;j++){
val[2].pElements[j][i]= val[1].pElements[i][j];
}
}
printf("\nMatrix %d is: \n",x);
x=2;
for(i=1;i<=col;i++){
for(j=1;j<=row;j++){
printf("%d ",val[x].pElements[i][j]);
}
printf("\n");
}
}
main(){
int choice;
int row,col;
int i,j,x;
printf(" !MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!MATRIX!\n");
printf("--------------------------------------------------------------------------------\n");
printf("OPERATION OF MATRICES\n");
printf("\n1)Matrix Addition");
printf("\n2)Matrix Subtraction");
printf("\n3)Matrix Multiplications");
printf("\n4)Computation of determinant");
printf("\n5)Summation of rows and columns");
printf("\n6)Matrix Inverse");
printf("\n7)Matrix Transpose");
printf("\n\nWhich operation to work on: ");
scanf("%d",&choice);
switch(choice){
case 1:
system("cls");
printf("MATRIX ADDITION");
x=1;//assigning matrix 1
matrixone(x);
print(x);
x=2;//assigning matrix 2
matrixone(x);
print(x);
x=3;//assigning matrix 3 (sum)
adding(x);
print(x);
break;
case 2:
system("cls");
printf("MATRIX SUBTRACTION");
x=1;//assigning matrix 1
matrixone(x);
print(x);
x=2;//assigning matrix 2
matrixone(x);
print(x);
x=3;//assigning matrix 3 (difference)
subtract(x);
print(x);
break;
case 3:
system("cls");
printf("MATRIX MULTIPLICATION");
x=1;//assigning matrix 1
matrixone(x);
print(x);
x=2;//assigning matrix 2
matrixone(x);
print(x);
x=3;//assigning matrix 3 (sum)
mult(x);
print(x);
break;
case 4:
system("cls");
printf("DETERMINANT OF A MATRIX");
break;
case 5:
system("cls");
printf("SUMMATION OF ROWS and COLUMNS");
break;
case 6:
system("cls");
printf("MATRIX INVERSE");
break;
case 7:
system("cls");
printf("MATRIX TRANSPOSE");
x=1;//assigning a matrix
matrixone(x);
print(x);
transpose(x);
break;
default:printf("Invalid Entry");
}
getch();
}
I only need help in knowing the problem in the passed by value of adding(). The program just stops working when the addition process takes place. Need Help Thanks!