C/Visual C - COMO CALCULO TOTAL DE UNA COLUMNA DE UNA MATRIZ??

 
Vista:

COMO CALCULO TOTAL DE UNA COLUMNA DE UNA MATRIZ??

Publicado por lucho (3 intervenciones) el 18/06/2006 01:24:14
HOLA, NECESITO AYUDA CON UNA PARTE DEL CODIGO QUE NO ME SALE, TENGO UNA MATRIZ DE 4x4 (LA DECLARE DE 5x5 PARA NO UTILIZARLA EN LA POSICION 0) Y QUIERO HACER LA SUMA TOTAL DE LOS VALORES DE LA COLUMNA UNO PERO NO ME SALE!! SIEMPRE ME TIRA CERO DE TOTAL, QUE ESTOY HACIENDO MAL ?? ? ? ? ACA LES DEJO EL CODIGO EN C (EL PRIMER FOR IGNORENLO , EL PROBLEMA ESTA EN EL SEGUNDO FOR)

DESDE YA MUCHAS GRACIAS A QUIEN ME PUEDA DAR UNA IDEA .

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

void main()
{
float vprecio[5]={0};
float matriz[5][5]={0};
float valor,cantidad,suma;
int i,articulo,articulo1,establecimiento,establecimiento1;

for (i=1;i<=4;i++)

{
printf("Ingrese el n£mero del art¡culo (de 1 a 4): ");
scanf("%d",&articulo);
// printf("Ingrese la descripci¢n del art¡culo(nombre): ");
// fflush(stdin);
// gets(descripcion);
printf("Ingrese el valor del art¡culo: ");
scanf("%f",&valor);
vprecio[articulo]=valor;
}

for(i=1;i<=4;i++) <<<< -----------HAY ALGO MAL ACA ?? ? ? ?
{
printf("ingrese no. establecimiento: ");
scanf("%d",&establecimiento1);
printf("ingrese no. articulo: ");
scanf("%d",&articulo1);
printf("Ingrese cantidad: ");
scanf("%f",&cantidad);
matriz[establecimiento][articulo1]=matriz[establecimiento][articulo1]+cantidad;
}

for (i=1;i<=4;i++)
{
suma=matriz[i][1]+suma;
}
printf("SUMA ES IGUAL A: %f",suma); <<<<<<---- ESTO ES LO QUE NO ME SALE!!!
getch();
} //fin main
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:COMO CALCULO TOTAL DE UNA COLUMNA DE UNA MATRIZ

Publicado por Alberto Menendez Romero (16 intervenciones) el 18/06/2006 20:32:01
pues tu problema es que en la ultima instruccion de la segunta sentencia for, es decir, el segundo ciclo, en la instruccion

matriz[establecimiento][articulo1]=matriz[establecimiento][articulo1]+cantidad;

tienes puesto "establecimiento", y esa variable nunca las haz utilizado, por lo que contiene numeros que no son correctos.. haciendo estos posiciones incorrectas en la matriz.. por lo que si cambias establecimiento por establecimiento1 (que es la variable a la cual si le introduces valores por el teclado), la suma dejara de ser cero....

prueba cambiando establecimiento por establecimiento1. ya lo hice y funciona

suerte !!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar