Answer the question
In order to leave comments, you need to log in
The parallel under the secondary diagonal is not sorted correctly. What is wrong and what needs to be fixed?
I can't figure out how to sort the parallel under the secondary diagonal in ascending order.
#include<iostream>
#include <cstring>
#include<cmath>
#include<cstdlib>
#include<conio.h>
#include<ctime>
#include<windows.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "RUS");
srand(time(NULL));
const int n = 5;
double a[n][n], buf;
int k = 1;
cout << "Массив a" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j] = rand() % 20 - 10;
cout << "a[" << i << "][" << j << "] = " << a[i][j] << "\t";
}
cout << endl;
cout << endl;
}
for (int i = 0; i < n; i++)
{
for (int j = n - 1; j > i; j--)
{
if (a[i][n - 1 - i + k] > a[i+1][n - 1 - i + k-1])
if (a[5][j] > a[5][j - 1])
{
buf = a[i][n - 1 - i + k];
a[i][n - 1 - i + k] = a[i + 1][n - 1 - i + k - 1];
a[i + 1][n - 1 - i + k - 1] = buf;
}
}
}
cout << endl;
cout << "Отсортированная параллель побочной диагонали расположенной под диагональю" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << "a[" << i << "][" << j << "] = " << a[i][j] << "\t";
}
cout << endl;
cout << endl;
}
system("PAUSE");
}
Answer the question
In order to leave comments, you need to log in
Catch this code
//g++ 7.4.0
https://qna.habr.com/q/1088148
#include<iostream>
#include <cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "RUS");
srand(time(NULL));
const int n = 5;
double a[n][n], buf;
int k = 1;
cout << "Массив a" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j] = rand() % 20 - 10;
cout << "a[" << i << "][" << j << "] = " << a[i][j] << "\t";
}
cout << endl;
cout << endl;
}
vector<double> vd;
for (int i = 0; i < n; i++)
{
for (int j = 0;j<n;j++)
{
if(i==j)
break;
if(i==j+1)
vd.push_back(a[i][j]);
}
}
sort(vd.begin(), vd.end());
for(int i=0;i<vd.size();i++)
cout <<vd[i]<< endl;
k=0;
for (int i = 0; i < n; i++)
{
for (int j = 0;j<n;j++)
{
if(i==j)
break;
if(i==j+1){
a[i][j] = vd[k];
k++;
}
}
}
cout << "Отсортированная параллель побочной диагонали расположенной под диагональю" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << "a[" << i << "][" << j << "] = " << a[i][j] << "\t";
}
cout << endl;
cout << endl;
}
}
Have you read this code at least once in its entirety? Every line? Here, put a mug in front of the monitor. Imagine that this is your student friend who is trying to copy an assignment from you, but does not understand anything. Here, explain to him, line by line, what is happening in your code, what he should do, how he should work.
It should immediately become clear to you that complete, absolute, distilled nonsense is written in one line.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question