Created
July 7, 2017 09:22
-
-
Save kabachuha/d9f359f23c62197813593ea90a210188 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> | |
using namespace std; | |
int main() | |
{ | |
const int size = 10; | |
int a[size], b[size], x, imax = 0, imin = 0; | |
for(int i = 0; i < size; i++) | |
{ | |
cin >> x; | |
a[i] = x; | |
if(a[i] >= a[imax]) | |
imax = i; | |
if(a[i] <= a[imin]) | |
imin = i; | |
} | |
for(int i = 0; i < size; i++) | |
{ | |
if(a[i] >= 0) | |
{ | |
b[i] = a[i] * (a[imin] * a[imin]); | |
} | |
else | |
{ | |
b[i] = a[i] * (a[imax] * a[imax]); | |
} | |
cout << b[i] << " "; | |
} | |
return 0; | |
} |
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> | |
using namespace std; | |
//#define DEF {{1,2,3,4}, {1,2,3,4}, {1,2,3,4}, {1,2,3,4}} | |
int main() | |
{ | |
const int size = 4; | |
int a[size][size]; | |
int i=0, j=0, k = 0; | |
int sum_main = 0, sum_sub = 0, sum_un_main = 0, sum_on_main = 0, sum_un_sub = 0, sum_on_sub = 0; | |
for(i = 0; i < size; i++) | |
for(j = 0; j < size; j++) | |
cin>> a[i][j]; | |
for(i = 0; i < size; i++) | |
for(j = 0; j < size; j++) | |
{ | |
if(i == j) | |
{ | |
sum_main += a[i][j]; | |
for(k = i-1; k >= 0; k--) | |
{ | |
sum_un_main += a[k][j]; | |
} | |
k =0; | |
for(k = i+1; k < size; k++) | |
{ | |
sum_on_main += a[k][j]; | |
} | |
k=0; | |
} | |
if(i + j == size - 1) | |
{ | |
sum_sub += a[i][j]; | |
for(k = i-1; k >= 0; k--) | |
{ | |
sum_un_sub += a[k][j]; | |
} | |
k =0; | |
for(k = i+1; k < size; k++) | |
{ | |
sum_on_sub += a[k][j]; | |
} | |
k=0; | |
} | |
} | |
cout <<"Main sum: "<<sum_main <<endl; | |
cout <<"Sub sum: "<< sum_sub <<endl; | |
cout << endl; | |
cout <<"Sum under main: "<< sum_un_main << endl; | |
cout <<"Sum on main: "<< sum_on_main << endl; | |
cout <<"Sum under sub: "<< sum_un_sub << endl; | |
cout <<"Sum on sub: "<< sum_on_sub << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment