#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void fk()
{
srand(time(0));
int n;
cout << "n:";
cin >> n;
int A[n][n];
cout << "\n\nMass:\n\n";
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
A[i][j]=rand()%10;
cout << A[i][j] << " ";
}
cout << endl;
int sum1 = 0;
int sum2 = 0;
sum1+=A[i][i];
sum2+=A[n-i-1][i];
cout << "\n\nSum1 = " << sum1;
cout << "\nSum2 = " << sum2;
cout << "\n\n";
if (A[j][0] > A[j+1][0]){
swap(A[j][0],A[j+1][0]);
cout << "\n\nMass sort:\n\n";
int main(){
fk();
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void fk()
{
srand(time(0));
int n;
cout << "n:";
cin >> n;
int A[n][n];
cout << "\n\nMass:\n\n";
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
A[i][j]=rand()%10;
cout << A[i][j] << " ";
}
cout << endl;
}
int sum1 = 0;
int sum2 = 0;
for(int i = 0; i<n; i++){
sum1+=A[i][i];
}
for(int i = 0; i<n; i++){
sum2+=A[n-i-1][i];
}
cout << "\n\nSum1 = " << sum1;
cout << "\nSum2 = " << sum2;
cout << "\n\n";
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
if (A[j][0] > A[j+1][0]){
swap(A[j][0],A[j+1][0]);
}
}
}
cout << "\n\nMass sort:\n\n";
for(int i = 0; i<n; i++){
for(int j = 0; j<n; j++){
cout << A[i][j] << " ";
}
cout << endl;
}
}
int main(){
fk();
return 0;
}