XeBuZer0

Padovan's secuence in C (recursive W/argc & argv)

Dec 21st, 2019 (edited)
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el n-ésimo término // ** // ** // ** //
  3. // ** // ** // ** // ** // de la secuencia de Padovan (recursivo) // ** // ** // ** // ** // ** //
  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 PadoRecu(long double n){
  15.     if (0<n) return (n<=2)?1:PadoRecu(n-2)+PadoRecu(n-3);
  16. }
  17.  
  18. void main(int argc, const char **argv){
  19.     long double aux;
  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*)&aux);
  27.     printf("\n El resultado con %4.0Lf es: %4.0Lf \n", aux, PadoRecu(aux));
  28. }
Add Comment
Please, Sign In to add comment