|
std::vector matrix(N, std::vector(M))
|
bet | 5/5 | Sana | 13.05.2024 | Hajmi | 340,43 Kb. | | #229987 |
Bog'liq 8-variantmustaqilishistd::vector> matrix(N, std::vector(M));
std::vector diagonalElements;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
matrix[i][j] = 125 + rand() % (1000 - 125 + 1); // Generate random numbers in [125, 1000]
StringGrid1->Cells[j][i] = IntToStr(matrix[i][j]);
if (i == j) { // Diagonal element
diagonalElements.push_back(matrix[i][j]);
}
}
}
// Sort diagonal elements in descending order
std::sort(diagonalElements.begin(), diagonalElements.end(), std::greater());
// Convert sorted diagonal elements to a string and display them in Label1
String diagStr = "";
for (int num : diagonalElements) {
diagStr += IntToStr(num) + " ";
}
Label1->Caption = Trim(diagStr); // Correctly trim and set the caption
}
Dastur natijasi
|
| |