XeBuZer0

Fibonacci's secuence in C (direct W/argc & argv)

Dec 21st, 2019 (edited)
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el n-ésimo término // ** // ** // ** //
  3. // ** // ** // ** // ** // de la secuencia de Fibonacci (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 <stdlib.h>
  13. #include <string.h>
  14.  
  15. #define Phi (1.0+sqrt(5.0))/2.0
  16.  
  17. long double FiboDire(long double n);
  18.  
  19. void main(int argc, const char **argv){
  20.     const long double x;
  21.     if (argc != 2){
  22.         extern int errno;
  23.         errno = 22;
  24.         fprintf(stderr, "Uso: %s <NÚMERO NATURAL>\n Code error: %d\n %s\n",*(argv+0), errno, strerror(errno));
  25.         exit(EXIT_FAILURE);
  26.     }
  27.     sscanf(*(argv+1), "%Lf", (long double*)&x);
  28.     if (0<x) printf("El resultado con %4.0Lf es: %4.0Lf\n", x, FiboDire(x));
  29. }
  30.  
  31. long double FiboDire(long double n){
  32.     if (0<n) return (pow(Phi,n)-pow((1.0-Phi),n))/sqrt(5.0);
  33. }
Add Comment
Please, Sign In to add comment