XeBuZer0

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

Dec 21st, 2019 (edited)
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el n-ésimo término // ** // ** // ** //
  3. // ** // ** // ** // ** // de la secuencia de Padovan (Iterativo) // ** // ** // ** // ** // ** //
  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 PadoIter(long double n);
  15.  
  16. void main(int argc, const char **argv){
  17.     long double x;
  18.     if (argc != 2){
  19.         extern int errno;
  20.         errno = 22;
  21.         fprintf(stderr, "Uso: %s <NÚMERO NATURAL>\n Code error: %d\n %s\n",*(argv+0), errno, strerror(errno));
  22.         exit(EXIT_FAILURE);
  23.     }
  24.     sscanf(*(argv+1), "%Lf", (long double*)&x);
  25.     printf("\n El resultado con %4.0Lf es: %4.0Lf \n", x, PadoIter(x));
  26. }
  27.  
  28. long double PadoIter(long double n){
  29.     register long double a=0, b=0, c=0, S=0, cont=1;
  30.     for (a=0,b=1,c=1,cont=1;cont<n;cont++){
  31.         S = a+b;
  32.         a = b;
  33.         b = c;
  34.         c = S;
  35.     }
  36.     return S;
  37. }
Add Comment
Please, Sign In to add comment