/
somarMatriz.cpp
89 lines (50 loc) · 1.27 KB
/
somarMatriz.cpp
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
#include<stdio.h>
#include<conio.h>
float matriz[2][2];
void obterNumero(){
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
printf("Digite quatro numeros [%d][%d]: ", i, j);
scanf("%f", &matriz[i][j]);
}
}
}
float somaNumero(){
float soma = 0;
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
soma = soma + matriz[i][j];
}
}return soma;
}
float mediaNumero(){
return somaNumero() / 4;
}
float menorNumero(){
float menor = matriz[0][0];
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
if(menor > matriz[i][j]){
menor = matriz[i][j];
}
}
}return menor;
}
float maiorNumero(){
float maior = matriz[0][0];
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
if(maior < matriz[i][j]){
maior = matriz[i][j];
}
}
}return maior;
}
main(){
obterNumero();
printf("O valor da soma dos numeros da matriz : %0.1f \n\n", somaNumero());
printf("O valor da media dos numeros da matriz : %0.1f \n\n", mediaNumero());
printf("O menor Numero da matriz : %0.1f \n\n", menorNumero());
printf("O maior Numero da matriz : %0.1f", maiorNumero());
getch();
}