So I have to make a program that can determinate the maximum from the diagonal of a matrix. Than I have to swap it's place of the first variable of the matrix (a[1][1]) with the maximum of that matrix, the other elements beeing unchanged.
Here is my code:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int a[20][20];
int main(){
    int i, j, n1, n2, max;
    printf ("\nIntroduceti numarul de coloane pentru matricea A: ");
    scanf (" %d", &n2);
    printf ("\nIntroduceti numarul de randuri pentru matricea A: ");
    scanf (" %d", &n1);
    printf("\nIntroduceti elementele primei matrice: ");
    for(i=1;i<=n1;i++){
        for(j=1;j<=n2;j++){
            printf("\na[%d][%d] = ", i, j);
            scanf("%d",&a[i][j]);
        }
    }
    printf("\nMatricea A este:\n");
    for(i=1;i<=n1;i++){
        printf("\n");
        for(j=1;j<=n2;j++){
            printf("%d\t",a[i][j]);
        }
    }
    do {
        for(i=1;i<=n1;i++){
            if(a[i][i]>max) {
                max=a[i][i];
            }
        }
    } while (i<=n1);
    printf ("\nMaximul de pe diagonala este: %d", max);
    a[1][1]=a[1][1]^max;
    max=max^a[1][1];
    a[1][1]=max^a[1][1];
        for(i=1;i<=n1;i++){
        printf("\n");
        for(j=1;j<=n2;j++){
            printf("%d\t",a[i][j]);
        }
    }
    return 0;
}
What I did wrong? My program swaps only the maximum with the first variable a[1][1], but forgets to place a[1][1] where the maximum is.