Advertisement
lineoff

fctfact

Dec 14th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. //fonction de factorielle en notion de recursivité
  4. double factorielle(int a){
  5.     if (!a || a == 1) {
  6.         /*
  7.          !a <=> a == 0
  8.          */
  9.         return 1;
  10.     }else{
  11.         return a*factorielle(a-1);
  12.     }
  13. }
  14. int main(){
  15.     // declaration
  16.     int a;
  17.    
  18.     printf("Donner la valeur a caculer: ");
  19.     // la valeur doit etre >=0
  20.     do {
  21.         scanf("%d",&a);
  22.     } while (a<0);
  23.     printf("factorielle de %d est: %0.f\n",a,factorielle(a));
  24.     //%0.f <=> 0 nbr apré la vergule.
  25.     getch();
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement