#include <stdio.h>
int main(){
    int m, n;
    int a[100][100];
    printf("nhap so hang m: ");
    scanf("%d", &m);
    printf("nhap so cot n: ");
    scanf("%d", &n);
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            printf("a[%d][%d] = ", i, j);
            scanf("%d", &a[i][j]);
        }
    }
    printf("\nma tran vua nhap:\n");
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            printf("%d\t", a[i][j]);
        }
        printf("\n");
    }
    int x;
    int found = 0;
    printf("\nnhap x can tim: ");
    scanf("%d", &x);
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            if(a[i][j] == x){
                found = 1;
                break;
            }
        }
    }
    if(found){
        printf("tim thay %d trong ma tran\n", x);
    } else {
        printf("Khong tim thay %d\n", x);
    }
    if(m == n){
        int sumChinh = 0, sumPhu = 0;
        printf("\ncac phan tu duong cheo chinh: ");
        for(int i = 0; i < n; i++){
            printf("%d ", a[i][i]);
            sumChinh += a[i][i];
        }
        printf("\ntong duong cheo chinh: %d\n", sumChinh);
        printf("cac phan tu duong cheo phu: ");
        for(int i = 0; i < n; i++) {
            printf("%d ", a[i][n - 1 - i]);
            sumPhu += a[i][n - 1 - i];
        }
        printf("\ntong duong cheo phu: %d\n", sumPhu);
    } else {
        printf("\nkphai ma tran vuong nen kco duong cheo!\n");
    }
    return 0;
}