Advertisement
Kl43z

Factorial Dado Vuelta

Oct 28th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int vuelta (int y);
  4. int factorialV(int x);
  5. int main(){
  6.     int input;
  7.     printf ("Ingrese un número para calcular su factorial invertido:\n");
  8.     scanf ("%d", &input);
  9.     //printf ("El factorial corresponde a: %.0f\n", factorial(input));
  10.     printf ("El factorial invertido corresponde a: %d\n", factorialV(input));
  11.     return 0;
  12.  
  13. }
  14.  
  15.  
  16. int factorialV(int x){
  17.    int i,temp;
  18.    int fact;
  19.    temp=x-1;
  20.    fact=x;
  21.    if(x>=1){   
  22.        for(i=temp;i>=1;i--){
  23.           fact*=temp;
  24.           temp-=1;
  25.        }
  26.        
  27.     }
  28.     else if(x==0){
  29.         fact=1;    
  30.        
  31.     }
  32.  
  33.         fact=vuelta(fact);
  34.         return fact;
  35.    
  36.    
  37. }
  38.  
  39. int vuelta(int y){
  40.     int rest,inv=0;
  41.     while(y!=0){
  42.         rest=y%10;
  43.         y=y/10;
  44.         inv=inv*10+rest;
  45.     }
  46.     return inv;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement