This repository has been archived on 2019-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/TP2/E4.c
2016-03-09 08:28:07 +01:00

40 lines
725 B
C

/* Tableau des différences */
#include <stdio.h>
#define N 10
void soustraire(int A[N], int R[N], int n) {
int i;
for (i = 0; i < n-1; i++) {
R[i] = A[i+1] - A[i];
}
}
void afficherTableau(int A[N], int n) {
int i;
for (i = 0; i < n; i++) {
printf("%11i ", A[i]);
}
printf("\n");
}
int main() {
int X[N] = {2,8,-3,5,9,-4,-2,0,1,16};
int DX[N][N];
int i;
printf("-- X ");
afficherTableau(X, N);
soustraire(X, DX[0], N);
printf("-- D1X");
afficherTableau(DX[0], N-1);
for (i = 0; i < N-1; i++) {
soustraire(DX[i], DX[i+1], N-i);
printf("-- D%dX", i+1);
afficherTableau(DX[i], N-i-1);
}
return 0;
}