Triangle Pascal Probleme
Bonjour,
J'ai un probleme
J'ai le schema suivant :
2
12
112
1112
111112
1111112
JE SOUHAITE AVOIR LE SCHEMA SUIVANT
2
22
212
2112
211112
2111112
ET VOILA MON CODE :
J'ai un probleme
J'ai le schema suivant :
2
12
112
1112
111112
1111112
JE SOUHAITE AVOIR LE SCHEMA SUIVANT
2
22
212
2112
211112
2111112
ET VOILA MON CODE :
#include <stdio.h>
#include <stdlib.h>
int main()
{int T[20][20];
int i ,j,n=5 ;
for(i=0;i<=n;i++){
for (j=0;j<=i;j++){
if(T[i]==T[j]){printf("2");}
else
printf("1 ");
}
printf("\n");
}
}
1 réponse
-
Bonjour,
Pour moi ce que tu cherches à faire ne correspond pas au triangle de Pascal au sens usuel.
pascal.c
#include <stdio.h> void f(FILE * out, unsigned n) { unsigned i, j; for (i = 0; i < n; i++) { fprintf(out, "2"); for (j = 0; j + 1 < i; j++) { fprintf(out, "1"); } if (i > 0) { fprintf(out, "2"); } fprintf(out, "\n"); } } int main() { f(stdout, 10); return 0; }
... ce qui donne bien :
(mando@silk) (~) $ gcc pascal.c && ./a.out
2
22
212
2112
21112
211112
2111112
21111112
211111112
2111111112
Bonne chance