-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnto_0002-Matrici.cpp
More file actions
110 lines (60 loc) · 1.58 KB
/
Anto_0002-Matrici.cpp
File metadata and controls
110 lines (60 loc) · 1.58 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#define DIMX 4
#define DIMY 3
void leggiMat(double mat[DIMX][DIMY], int dimX, int dimY)
{
int x, y;
for (y=0; y<dimY; y++)
{
for (x=0; x<dimX; x++)
{
printf("Inserisci il numero per l'indice %d %d = ", x, y);
scanf("%lg", &mat[x][y]);
}
}
}
void stampaMat(double mat[DIMX][DIMY], int dimX, int dimY)
{
int x, y;
for (y=0; y<dimY; y++)
{
for (x=0; x<dimX; x++)
{
printf("\nSampo l'indice %d %d = %8g", x, y, mat[x][y]);
}
}
}
double sommaCornice(double mat[DIMX][DIMY], int dimX, int dimY)
{
double somma = 0;
int x, y;
for (y=0; y<dimY; y++)
{
if (y==0)
{
for (x=0; x<dimX; x++) somma += mat[x][y];
}
if (y==dimY)
{
for (x=0; x<dimX; x++) somma += mat[x][y];
}
else
{
somma += mat[0][y];
somma += mat[dimX][y];
}
}
printf("\ndebug somma= %lg", somma);
//cast a intero (il rigo sotto serve a provare se il programma funziona correttamente ma e' inutile)
printf("\nIntero = %d\n", (int)somma);
return somma;
}
int main()
{
double miaMat[DIMX][DIMY];
leggiMat(miaMat, DIMX, DIMY);
stampaMat(miaMat, DIMX, DIMY);
printf("\n\nLa somma dei valori presenti nella cornice e' = %lg", sommaCornice(miaMat, DIMX, DIMY));
printf("\n\n\n");
return 0;
}