Jump to content
Fórum Script Brasil
  • 0

Soma de colunas de matriz bidimensional


Alaplaia

Question

Bom dia.

É a primeira vez que vou fazer um programa com matriz bidimensional ,que é passada por parâmetro ao invés de criar dentro do módulo. O objetivo seria fazer a soma dos valores de uma coluna de uma matriz, que o usuário deve escrever a quantidade de linhas e colunas que acaba sendo as mesmas, sendo no máximo 5 linhas e colunas. Ele dá os seguintes erros:

5 C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp declaration of `A' as multidimensional array must have bounds for all dimensions except the first

C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp In function `int lerMatriz(int*, int*)':

14C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp `A' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

At global scope:

35 C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp declaration of `B' as multidimensional array must have bounds for all dimensions except the first

C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp In function `void mostrarMatriz(int*, int*)':

40 C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp `B' undeclared (first use this function)

C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp In function `int main()':

49 C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp cannot convert `int (*)[5]' to `int*' for argument `1' to `int lerMatriz(int*, int*)'

51 C:\Documents and Settings\User\Desktop\cpp\soma de colunas.cpp cannot convert `int (*)[5]' to `int*' for argument `1' to `void mostrarMatriz(int*, int*)'

#include <stdio.h>
#include <conio.h>

int lerMatriz(int A[][], int *i, int *j)
{
     int aux;
     printf("Digite um numero para determinar o tamanho de linhas e colunas da matriz bidimensional A: ");
     scanf("%d",&aux);
     for(*i=0;*i<aux;*i++)
     {
         for(*j=0;*j<aux;*j++)
         {
             printf("Digite um numero para a posicao:linha %d, coluna %d",*i,*j);
             scanf("%d",A[*i][*j]);
         }
     }
     *i=aux;
     *j=aux;
}

void somarMatriz(int A[][], int B[][], int *i, int *j)
{
     int soma=0, auxi, auxj;
     for (auxj=0;auxj<*j;auxj++)
     {
         for (auxi=0;auxi<*i;auxi++)
         {
             soma=soma+A[auxi][auxj];
         }
         B[1][auxj]=soma;
     }
}

void mostrarMatriz(int B[][], int *i, int *j)
{
     for (int auxi=0;auxi<*i;auxi++)
     {
         for (int auxj=0;auxj<*j;auxj++)
         {
             printf("A soma da coluna e: %d", B[1][*j]);
         }
     }
}


main()
{
      int A[5][5],B[1][5],i=0,j=0;
      lerMatriz(A,&i,&j);
      somarMatriz(A,B,&i,&j);
      mostrarMatriz(B,&i,&j);
      getch();
}

Edited by Alaplaia
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...