
Matriz Dinamica Simplificando Bucles
Publicado por Fucking (9 intervenciones) el 20/07/2015 03:53:39
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
/*quiero hacer correr dentro de el bucle for , ala funcion asi evito poner en cada funcion el bucle for cada vez que quiera hacer algo con la matriz aqui paso el codigo cual es el error?*/
#include <cstdio>
#include <cstdlib>
int suma_not_pair(int **pointmatriz){
int i=0,j=0,sumaimp=0;
if ((pointmatriz[i][j])%2!=0){
sumaimp+=pointmatriz[i][j];}
return sumaimp;
}
int main(){
//DECLARO LAS VARIABLES A UTILIZAR
int M=0,N=0 ,j=0,i=0,sumaimp;
printf("\n\tIngrese las filas\n\t");
scanf("%d",&M);
printf("\n\tIngrese las columnas \n\t");
scanf("%d",&N);
//DECLARO EL PUNTERO DE LA MATRIZ
int **pointmatriz;
//ALOJO EN LA MEMORIA LAS FILAS
pointmatriz=(int**) malloc(M*sizeof(int*));
//ALOJO EN LA MEMORIA LAS COLUMNAS
for(i=0;i<M;i++){
pointmatriz[i]=(int*)malloc(N*sizeof(int));
}
//LLENO LA MATRIZ
for(i=0;i<M;i++){
for(j=0;j<N;j++){
scanf("%d",&pointmatriz[i][j]);
}}
printf("\n\tLos valores de la matriz son\n\t");
//MUESTRO LA MATRIZ
for(i=0;i<M;i++){
for(j=0;j<N;j++){
printf("%d-",pointmatriz[i][j]);
}}
suma_not_pair(pointmatriz);
printf("\n\tLa suma de impares es de :%d\n\t",sumaimp);
for(i=0;i<M;i++){
free(pointmatriz[i]);
}
free(pointmatriz);
return EXIT_SUCCESS;
}
Valora esta pregunta


0