Matrices en c++
Publicado por Jorge E Güisa R (2 intervenciones) el 22/03/2018 07:40:24
Tengo un programa en c++ para leer una matriz. y muestra la matriz pero con 0.0000 en todas las posiciones. Si alguien me ayuda le agradecería.
Programa
Matriz
la primera fila son las filas y las columnas26 4
64.001 1099.016 2.533 101.500
63.001 0437.152 14.667 735.170
59.001 4224.130 31.233 2008.080
56.001 3765.130 8.600 725.602
44.001 1278.091 32.700 1067.031
41.001 2583.012 12.767 298.350
40.001 2584.120 12.867 199.020
36.001 2079.111 13.867 233.240
34.001 2077.110 17.400 252.290
33.001 2102.111 17.533 100.576
32.001 1371.111 7.167 363.310
31.001 0989.111 11.267 396.960
30.001 1653.111 4.133 60.740
28.001 0568.101 9.100 307.780
27.001 0771.100 12.667 856.716
24.001 2648.081 4.000 77.787
23.001 2366.071 8.100 311.710
19.001 1083.051 4.000 88.911
18.001 1683.041 9.600 725.110
17.001 0503.041 4.800 532.982
16.001 0582.031 13.033 1224.879
13.001 0086.021 6.067 566.692
11.001 0293.021 4.067 218.480
10.001 0345.021 2.567 119.360
5.001 0373.011 7.633 590.070
8.002 0026.071 2.067 19.830
Programa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using std::cout;
using std::cin;
using std::endl;
int FILAS = 15 ;
int COLS = 4 ;
int a = 20 ;
int** leerMatriz(char *fileName) {
FILE *fp = fopen(fileName, "r");
if (fp == NULL) {
exit(EXIT_FAILURE);
}
char linea[50];
fgets(linea, 49, fp);
char *token = strtok(linea, " ");//10 6
FILAS = atoi(token);
token = strtok(NULL, " ");
COLS = atoi(token);
int **matriz = new int*[FILAS];
for (int i = 0; i < FILAS; i++) {
matriz[i] = new int[COLS];
fgets(linea,49, fp);
token = strtok(linea, " ");
matriz[i][0] = atoi(token);
for (int j = 1; j < COLS; j++) {
token = strtok(NULL, " ");
matriz[i][j] = atoi(token);
}
}
fclose(fp);
return matriz;
}
int main()
{
int **Experiencia = leerMatriz("Realizados.txt");
a = FILAS;
puts("");
printf(" El valor de A es %d \n", a);
puts("");
puts("");
puts("");
cout << " La matriz completa es: ";
puts("");
int k = 0 ; /* indices para filas */
int Contratos = 0 ; /* indices los contratos a contar */
puts("------------------------");
for (Contratos; Contratos<(FILAS); Contratos++) {
for (k=0; k<COLS; k++) {
printf(" %8.3f ", Experiencia[Contratos][k] );
}
puts("");
}
system("pause");
printf(" Fin del programa \n");
puts("");
puts("");
puts("");
system("pause");
return 0;
}
Matriz
la primera fila son las filas y las columnas26 4
64.001 1099.016 2.533 101.500
63.001 0437.152 14.667 735.170
59.001 4224.130 31.233 2008.080
56.001 3765.130 8.600 725.602
44.001 1278.091 32.700 1067.031
41.001 2583.012 12.767 298.350
40.001 2584.120 12.867 199.020
36.001 2079.111 13.867 233.240
34.001 2077.110 17.400 252.290
33.001 2102.111 17.533 100.576
32.001 1371.111 7.167 363.310
31.001 0989.111 11.267 396.960
30.001 1653.111 4.133 60.740
28.001 0568.101 9.100 307.780
27.001 0771.100 12.667 856.716
24.001 2648.081 4.000 77.787
23.001 2366.071 8.100 311.710
19.001 1083.051 4.000 88.911
18.001 1683.041 9.600 725.110
17.001 0503.041 4.800 532.982
16.001 0582.031 13.033 1224.879
13.001 0086.021 6.067 566.692
11.001 0293.021 4.067 218.480
10.001 0345.021 2.567 119.360
5.001 0373.011 7.633 590.070
8.002 0026.071 2.067 19.830
Valora esta pregunta


0