manuplating matrix operation(transpose, negation, addition, and mutipication) using functions in c
Posted
by user292489
on Stack Overflow
See other posts from Stack Overflow
or by user292489
Published on 2010-05-09T21:34:18Z
Indexed on
2010/05/09
21:38 UTC
Read the original article
Hit count: 400
i was trying to manuplate matrices in my input file using functions. my input file is, A 3 3 1 2 3 4 5 6 7 8 9 B 3 3 1 0 0 0 1 0 0 0 1 C 2 3 3 5 8 -1 -2 -3 D 3 5 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 E 1 1 10 F 3 10 1 0 2 0 3 0 4 0 5 0 0 2 3 -1 -3 -4 -3 8 3 7 0 0 0 4 6 5 8 2 -1 10
i am having trouble in impementing the funcitons that i declared. i assumed my program will perform those operations: transpose, negate, add, and mutiply matices according to the users choise:
/* once this program is compliled and excuted, it will perform the basic matrix operations: negation, transpose,a\
ddition, and multiplication. */
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
int readmatrix(FILE *input, char martixname[6],int , mat[10][10], int i, int j);
void printmatrix(char matrixname[6], int mat[10][10], int i, int j);
void Negate(char matrixname[6], int mat[10][10], int i, int j);
void add(char matrixname[6], int mat[10][10],int i, int k);
void multiply(char matrixname[], int mat[][10], char A[], int i, int k);
void transpose (char matrixname[], int mat[][10], char A[], int);
void printT(int mat[][10], int);
int selctoption();
char selectmatrix();
int main(int argc, char *argv[])
{ char matrixtype[6];
int mat[][10];
FILE *filein;
int size;
int optionop;
int matrixop;
int option;
if (argc != 2)
{ printf("Usage: excutable input.\n");
exit (0);
}
filein = fopen(argv[1], "r");
if (!filein)
{ printf("ERROR: input file not found.\n");
exit (0);
}
size = readmatrix (filein, matrixtype);
printmatrix(matrix[][10], size);
option = selectoption();
matrixtype = selectmatrix();
//printf("You have: %5.2f ", deposit);
optionop = readmatrix(option, matrix[][10], size);
if (choiceop == 6)
{ printf("Thanks for using the matrix operation program.\n");
exit(0);
}
printf("Please select from the following matrix operations:\n")
printf("\t1. Print matrix\n");
printf("\t2. Negate matrix\n");
printf("\t3. Transpose matrix\n");
printf("\t4. Add matrices\n");
printf("\t5. Multiply matrices\n");
printf("\t6. Quit\n");
fclose(filein);
return 0;
}
do
{ printf("Please select option(1-%d):", optionop);
scanf("%d", &matrixop);
}while(matrixop <= 0 || matrixop > optionop);
void readmatrix (FILE *in, int mat[][10], char A[], int i, int j)
{ int i=0,j = 0;
while (fscanf(in, "%d", &mat[i][j]) != EOF)
return 0;
}
// i would apprtaite anyones feedback. //thank you!
© Stack Overflow or respective owner