Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <ctime>
- using namespace std;
- #define M 5
- #define N 5
- int maxSumInRow(int array[][N], size_t rows);
- void fillTheArray(int array[][N], size_t rows);
- void printTheArray(int array[][N], size_t rows);
- int main(){
- setlocale(LC_ALL, "Bulgarian");
- srand(time(NULL));
- int array[M][N];
- fillTheArray(array, M);
- printTheArray(array, M);
- cout << endl;
- cout << "Максималната сума на ред е " << maxSumInRow(array, M) << endl;
- return 0;
- }
- //Е) намиране на реда на матрицата, който има максимална сума;
- int maxSumInRow(int array[][N], size_t rows){
- int max=0;
- int tmp=0;
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- tmp += array[i][j]; // 1 2 3 4 = 13 =tmp
- // 5 6 7 8 = 26
- }
- if (tmp > max){
- max = tmp;
- }
- tmp = 0;
- }
- return max;
- }
- //слагам стойности
- void fillTheArray(int array[][N], size_t rows){
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- array[i][j] = rand() % 5;
- }
- }
- }
- //принтирам масив
- void printTheArray(int array[][N], size_t rows){
- cout << "Оригиналната матрица е това : " << endl;
- for (size_t i = 0; i < M; i++)
- {
- for (size_t j = 0; j < N; j++){
- cout << array[i][j] << "\t";
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment