XeBuZer0

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

Dec 21st, 2019 (edited)
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el n-ésimo término // ** // ** // ** //
  3. // ** // ** // ** // ** //  de la secuencia de Padovan (directo)  // ** // ** // ** // ** // ** //
  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 <math.h>
  10. #include <errno.h>
  11. #include <stdio.h>
  12. #include <tgmath.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <complex.h>    /* Standard Library of Complex Numbers */
  16. #define Ro                                          cbrtl((1.0/2.0) + ((1.0/6.0)*(sqrtl(23.0/3.0)))) +                                         cbrtl((1.0/2.0) - ((1.0/6.0)*(sqrtl(23.0/3.0))))
  17. #define Ro1 (-1.0 * (1.0/2.0) + I*sqrt(3.0)/2.0 ) * cbrtl((1.0/2.0) + ((1.0/6.0)*(sqrtl(23.0/3.0)))) + (-1.0 * (1.0/2.0) - I*sqrt(3.0)/2.0 ) * cbrtl((1.0/2.0) - ((1.0/6.0)*(sqrtl(23.0/3.0))))
  18. #define Ro2 (-1.0 * (1.0/2.0) - I*sqrt(3.0)/2.0 ) * cbrtl((1.0/2.0) + ((1.0/6.0)*(sqrtl(23.0/3.0)))) + (-1.0 * (1.0/2.0) + I*sqrt(3.0)/2.0 ) * cbrtl((1.0/2.0) - ((1.0/6.0)*(sqrtl(23.0/3.0))))
  19.  
  20. long double PadoDire(long double n);
  21.  
  22. void main(int argc, const char **argv){
  23.     printf("Ro  = %+4.15Lf \n", Ro);
  24.     printf("Ro1 = %+4.15Lf  %+4.15Lfi\n", creal(Ro1), cimag(Ro1));
  25.     printf("Ro2 = %+4.15Lf  %+4.15Lfi\n", creal(Ro2), cimag(Ro2));
  26.     long double x;
  27.     if (argc != 2){
  28.         extern int errno;
  29.         errno = 22;
  30.         fprintf(stderr, "Uso: %s <NÚMERO NATURAL>\n Code error: %d\n %s\n",*(argv+0), errno, strerror(errno));
  31.         exit(EXIT_FAILURE);
  32.     }
  33.     sscanf(*(argv+1), "%Lf", (long double*)&x);
  34.     if (0<=x) printf("\n El resultado con %4.0Lf es: %4.0Lf \n", x, PadoDire(x+4));
  35. }
  36.  
  37. long double PadoDire(long double n){
  38.     if (0<n) return creal(cpowl(Ro,n)/(3*cpowl(Ro,2) - 1) + cpowl(Ro1,n)/(3*cpowl(Ro1,2) - 1) + cpowl(Ro2,n)/(3*cpowl(Ro2,2) - 1));
  39. }
Add Comment
Please, Sign In to add comment