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: 363

Filed under:
|
|

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

Related posts about c

    Related posts about home

    • encfs error while decoding the data

      as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
      I have installed encfs and started using it to secure all my personal & office data and it was working absolutely fine until 2 hours back. The setup is like this. I have a folder in Copy folder called OfficeData which gets synchronized with my Copy folder When I login into the system I use… >>> More

    • Magento, NGINX, PHP-FPM, APC, MEMCACHED, 16gb Ram CentOS, Spiking PHP-FPM to 100% CPU

      as seen on Server Fault - Search for 'Server Fault'
      I have been trying to resolve my issue of spiking cpu caused by php-fpm processes. I've reduced the php-fpm config settings to: pm = ondemand pm.max_children = 12 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 10 pm.max_requests = 500 php_admin_value[memory_limit] = 128M Problem… >>> More

    • Building Awesome WM

      as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
      Hello, I am following these steps in order to build Awesome window manager on 10.04 I am building 3.4 while the tutorial is for 3.1 I installed all of the specified dependencies including cairo. After running cd awesome-3.4 && make I get the following missing dependencies error: Running… >>> More

    • Building Awesome WM

      as seen on Server Fault - Search for 'Server Fault'
      Hello, I am following these steps in order to build Awesome window manager on 10.04 I am building 3.4 while the tutorial is for 3.1 I installed all of the specified dependencies including cairo. EDIT I ran: sudo apt-get install libxcb-xtest0-dev libxcb-property1-dev libxdg-basedir-dev libstartup-notification0-dev… >>> More

    • Building Awesome WM

      as seen on Super User - Search for 'Super User'
      Hello, I am following these steps in order to build Awesome window manager on 10.04 I am building 3.4 while the tutorial is for 3.1 I installed all of the specified dependencies including cairo. EDIT I ran: sudo apt-get install libxcb-xtest0-dev libxcb-property1-dev libxdg-basedir-dev libstartup-notification0-dev… >>> More