XeBuZer0

Factorial in C with recursivity and ARGC/ARGV

Dec 20th, 2019 (edited)
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el factorial de un // ** // ** // ** //
  3. // ** // ** // ** // ** // número natural utilizando recursividad // ** // ** // ** // ** // ** //
  4. // ** // ** // ** // * Licenciado bajo GNU General Public License (GPL) 3.0 * // ** // ** // ** //
  5. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  6. /* ** // ** // ** // ** // ** //  * F v q _ U k r a N a z i s ! * // ** // ** // ** // ** // ** */
  7. /* ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <errno.h>
  13.  
  14. long double fact(long double a){
  15.     if (0<a) return (a==1)?1:a*fact(a-1);
  16. }
  17.  
  18. void main(int argc, const char **argv){
  19.     long double x=0;
  20.     if (argc != 2){
  21.         extern int errno;
  22.         errno = 22;
  23.         fprintf(stderr, "Uso: %s <NÚMERO NATURAL>\n Code error: %d\n %s\n",*(argv+0), errno, strerror(errno));
  24.         exit(EXIT_FAILURE);
  25.     }
  26.     sscanf( *(argv+1) , "%Lf", (long double*) &x);
  27.     if (0<x) printf("El factorial de %4.0Lf es %4.0Lf \n", x, fact(x));
  28. }
Add Comment
Please, Sign In to add comment