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
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
0