-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (35 loc) · 1.06 KB
/
main.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
#include <iostream>
using namespace std;
/*
4 – Faça um programa que permita ao usuário entrar com uma matriz 3x3
números inteiros. Em seguida, gere um vetor unidimensional pela soma dos
números de cada coluna da matriz e mostre na tela este vetor. Por exemplo, a
matriz:
5 -8 10
1 2 15
25 10 7
Vai gerar um vetor, onde cada posição é a soma das colunas da matriz. A
primeira posição será 5 + 1 + 25, e assim por diante:
31 4 3
*/
int main() {
int matriz[3][3];
int somaColunas[3] = {0};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << "Digite o elemento da linha " << i + 1 << " e coluna " << j + 1 << ": ";
cin >> matriz[i][j];
}
}
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
somaColunas[j] += matriz[i][j];
}
}
cout << "\nVetor com a soma de cada coluna:\n";
for (int i = 0; i < 3; i++) {
cout << somaColunas[i] << " ";
}
system("PAUSE");
return 0;
}