Thread: Matrix problem I think

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Angry Matrix problem I think

    This program is supposed to ask for the number of rows and columns of a matrix, then ask for every element separately and then print the sum of every row, but it always shows 0.00000.

    What is wrong and why?

    #include <stdio.h>

    #define FILAS_MAX 10
    #define COLS_MAX 10

    main(void)
    {
    float m[FILAS_MAX][COLS_MAX],sumafila;
    int filas,cols,fila,col;

    do{
    printf("Numero de filas de la matriz: ");
    scanf("%d",&filas);
    }while(filas<1||filas>FILAS_MAX);

    do{
    printf("Numero de columnas de la matriz: ");
    scanf("%d",&cols);
    }while(cols<1||cols>COLS_MAX);

    printf("Introduzca los valores de la matriz.\n");
    for(fila=0;fila<filas;fila++)
    for(col=0;col<cols;col++){
    printf("m[%d][%d]: ",fila,col);
    scanf("%d",&m[fila][col]);
    }

    for(fila=0;fila<filas;fila++){
    sumafila=0;
    for(col=0;col<cols;col++)
    sumafila+=m[fila][col];
    printf("Suma de la fila %d=%f\n",fila,sumafila);
    }
    printf("Gracias por usar software Xuaco!");
    }
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    [email protected]

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You're mixing floats and ints. Try changing this:
    >scanf("%d", &m[fila][col]);
    to this
    >scanf("%f", &m[fila][col]);
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Music Programming - Serial Matrix Display (Help needed)
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 04:28 PM
  3. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 04:16 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  5. Replies: 3
    Last Post: 12-22-2004, 07:29 PM