In operations on an array, it shows an incorrect result after the first row of the array

2

Why when calling the functions that multiply and divide each of the elements of the rows of an array, it only shows me the first multiplication of the first row of the array, and the other results show them as equal to zero?

#include <stdio.h>
#include <iostream>
#define SIZE 10

void sumarFilas(double a[][SIZE], int filas_sum);
void multiplicarFilas(double b[][SIZE], int filas_mul);
void dividirFilas(double c[][SIZE], int filas_div);

int main()
{
    int num_fil,i,j;

    printf("Ingresa el numero de filas: ");
    scanf("%d",&num_fil);
    printf("\n");

    double bid_array[num_fil][SIZE];

    for(i=0; i<num_fil; i++)
    {
        for(j=0; j<SIZE; j++)
        {
            printf("Ingresa el elemento que se encuentra en la posicion [%d][%d] del arreglo: ",i,j);
            scanf("%lf",&bid_array[i][j]);
        }
    }

    printf("\nLos elementos ingresados al arreglo son:");
    printf("\n");

    for(i=0; i<num_fil; i++)
    {
        for(j=0; j<SIZE; j++)
        {
          printf("     %.3lf",bid_array[i][j]); 
        }

        printf("\n");
    }

    sumarFilas(bid_array, num_fil);

    printf("\n");

    multiplicarFilas(bid_array, num_fil);

    printf("\n");

    dividirFilas(bid_array, num_fil);

    printf("\n");

    system("pause");
    return 0;
}

void sumarFilas(double a[][SIZE], int filas_sum)
{
    int i,j;

    double suma[filas_sum];

    for(i=0; i<filas_sum; i++)
    {
        for(j=0; j<SIZE; j++)
        {
            suma[i] += a[i][j];
        }
    }

    printf("\nLa suma de los elementos de cada fila del arreglo bidimensional es:");
    printf("\n");

    for(i=0; i<filas_sum; i++)
    {
        printf("%lf\n",suma[i]);
    }
}

void multiplicarFilas(double b[][SIZE], int filas_mul)
{
    int i,j;

    double multiplicar[filas_mul] = {1};

    for(i=0; i<filas_mul; i++)
    {
        for(j=0; j<SIZE; j++)
        {
            multiplicar[i] *= (b[i][j]);

        }
    }

    printf("\nLa multiplicacion de los elementos de cada fila del arreglo bidimensional es:");
    printf("\n");

    for(i=0; i<filas_mul; i++)
    {
        printf("%lf\n",multiplicar[i]);
    }
}

void dividirFilas(double c[][SIZE], int filas_div)
{
    int i,j;

    double dividir[filas_div] = {1};

    for(i=0; i<filas_div; i++)
    {
        for(j=0; j<SIZE; j++)
        {
            dividir[i] /= c[i][j]; 
        }
    }

    printf("\nLa division de los elementos de cada fila del arreglo bidimensional es:");
    printf("\n");

    for(i=0; i<filas_div; i++)
    {
        printf("%lf\n",dividir[i]);
    }
}
    
asked by Jesús Fragoso 21.12.2016 в 03:33
source

1 answer

2

You are incorrectly initializing the fixes:

double multiplicar[filas_mul] = {1};

Although it may seem otherwise, there you are creating an array in which only the first element will be worth 1 while the rest of the positions will be initialized to 0.

To set the arrangement correctly you will have to use a loop:

for(int i=0; i<filas_mul; i++)
  multiplicar[filas_mul]=1;
    
answered by 21.12.2016 в 07:17