• // Convert sorted diagonal elements to a string and display them in Label1 String diagStr = ""; for (int num : diagonalElements) {
  • std::vector matrix(N, std::vector(M))




    Download 340,43 Kb.
    bet5/5
    Sana13.05.2024
    Hajmi340,43 Kb.
    #229987
    1   2   3   4   5
    Bog'liq
    8-variantmustaqilishi

    std::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

    Download 340,43 Kb.
    1   2   3   4   5




    Download 340,43 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    std::vector matrix(N, std::vector(M))

    Download 340,43 Kb.