Skip to content

Instantly share code, notes, and snippets.

@jy95
Last active September 21, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jy95/676cea3c8ebeaa45a2b8 to your computer and use it in GitHub Desktop.
Save jy95/676cea3c8ebeaa45a2b8 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<limits.h>
/*Version 1 - Nombre à un chiffre*/
int n;
int main(){
int nombre;
int factorielle;
while((nombre=getchar()) != EOF ){
if (nombre == '\n') {
printf("Ligne vide \n");
continue;
}
if ( nombre < '0' || nombre > '9'){
printf("Pas un chiffre \n");
while(getchar() != '\n'){
}
continue;
}
if (getchar() == '\n') {
nombre=nombre-'0';
if (nombre >= 0 && nombre < 10) {
factorielle = 1;
for(;nombre > 0;nombre--){
factorielle*=nombre;
}
printf("resultat %d \n",factorielle);
continue;
}
while(getchar() != '\n') {
}
continue;
}
return 0;
}
}
/* Version 2
*
int n;
int main(){
int nombre;
int factorielle;
while((nombre=getchar()) != EOF ){
if (nombre == '\n') {
printf("Ligne vide \n");
continue;
}
if ( nombre < '0' || nombre > '9'){
printf("Pas un chiffre \n");
while(getchar() != '\n'){
}
continue;
}
if (getchar() == '\n') {
nombre=nombre-'0';
if (nombre >= 0 && nombre < 10) {
factorielle = 1;
for(;nombre > 0;nombre--){
factorielle*=nombre;
}
printf("resultat %d \n",factorielle);
continue;
}
while(getchar() != '\n') {
}
continue;
}
return 0;
}
}
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment