Your main issue is that the names of your variables introduce confusion.
In particular here, for (i = M; M - N > 0; i--)
the condition M-N > 0
introduces an infinite loop.
Everything becomes much simpler with better names selection.
Output
Entrez la valeur de N : 5
1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
#include <stdio.h>
int main() {
int N;
do {
printf("Entrez la valeur de N : ");
scanf("%d", &N);
} while (N <= 0 || N % 2 == 0);
for (int row = 1; row <= N; ++row) {
int n_blank = 2 * (row - 1);
for (int i = 0; i < n_blank; ++i)
printf(" ");
for (int j = row; j <= N; j++) {
printf(" %d", j);
}
for (int j = N-1; j >= row; j--) {
printf(" %d", j);
}
printf("
");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…