Ответы 1
#include <iostream>
#include <fstream>
const int ROWS = 5;
const int COLS = 5;
void readNumbersFromFile(int Z[ROWS][COLS]) {
std::ifstream inputFile("danie.txt");
if (inputFile.is_open()) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
inputFile >> Z[i][j];
}
}
inputFile.close();
} else {
std::cout << "Failed to open the file." << std::endl;
}
}
void printMatrix(const int Z[ROWS][COLS]) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
std::cout << Z[i][j] << " ";
}
std::cout << std::endl;
}
}
int main() {
int Z[ROWS][COLS];
readNumbersFromFile(Z);
std::cout << "Matrix Z:" << std::endl;
printMatrix(Z);
std::cout << "Result:" << std::endl;
for (int j = 0; j < COLS; j++) {
std::cout << Z[0][j] + Z[1][j] << " ";
}
std::cout << std::endl;
return 0;
}
ответы на свои вопросы
вопросы?