Created
November 20, 2012 05:36
-
-
Save vadimtsushko/4116234 to your computer and use it in GitHub Desktop.
Пример со статическим массивом
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <conio.h> | |
#include <time.h> | |
/*15. Задан двумерный массив. Найти сумму элементов первого столбца без одного последнего элемента, | |
сумму элементов второго столбца без двух последних, сумму элементов третьего столбца без трех последних и т. д. | |
Последний столбец не обрабатывается. Среди найденных сумм найти максимальную. | |
*/ | |
using namespace std; | |
void input( int x[100][100], int n , int m ) | |
{ | |
srand(time(0)); | |
for ( int i = 0; i < n; i++ ) | |
for ( int j = 0; j < m; j ++ ) | |
{ | |
x[i][j] = rand()%115+1; | |
} | |
} | |
void output( int x[100][100], int n , int m ) | |
{ | |
for ( int i = 0; i < n; i++ ) | |
{ | |
for ( int j = 0; j < m; j ++ ) | |
{ | |
cout << x[i][j] << " "; | |
} | |
cout << endl; | |
} | |
} | |
void summa ( int x[100][100], int n, int m ) | |
{ | |
int s,max; | |
max = -1; | |
for ( int j = 0; j < m-1; j++ ) | |
{ | |
s = 0; | |
for ( int i = 0; i < n-j-1; i++ ) | |
{ | |
s+= x[i][j]; | |
} | |
cout << "Сумма в столбце " << j << " = " << s << endl; | |
max = ( s > max ) ? s : max; | |
} cout << "Максимальный элемент = " << max; | |
} | |
int main() | |
{ int sum; | |
setlocale(LC_CTYPE, "Russian"); | |
int n, m, s = 0, i, j, max, k = 0; | |
int x [100][100]; | |
cout << "введите размерность :" << endl; | |
cout << "кол-во строк: "; cin >> n; | |
cout << "кол-во столбцов "; cin >> m; | |
cout << endl << "матрица: " << endl; | |
input ( x, n, m ); | |
output ( x, n, m); | |
cout << endl; | |
summa ( x, n, m ); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment