matrisde köşegeni sıralama

mail@pastecode.io avatar
unknown
c_cpp
a month ago
910 B
3
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int    board[10][10];
    
    /* Matrise rastgele değer ata */
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
            board[i][j] = rand() % 100;
    }

    /* Matrisi Yazdır */
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
            printf("%d\t", board[i][j]);
        printf("\n\n\n");
    }

    printf("\n\n");
    
    for(int i = 0; i < 10; i++)
    {
        for(int j = i + 1; j < 10; j++)
        {
            if(board[i][9 - i] > board[j][9 - j])
            {
                int temp = board[i][9 - i];
                board[i][9 - i] = board[j][9 - j];
                board[j][9 - j] = temp;
            }
        }
    }


    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
            printf("%d\t", board[i][j]);
        printf("\n\n\n");
    }
}
Leave a Comment