Advertisement
Alx09

fibo

May 13th, 2021
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main(){
  6.     int n, a, b, c, nrNumere = 0;
  7.     printf("numar= "); scanf("%u", &n);
  8.     if (n < 1) {
  9.         printf("Nu se poate scrie!\n");
  10.         return 0;
  11.     }
  12.     while (n)
  13.     {
  14.         a = 0;
  15.         b = 1;
  16.         while (a + b <= n)
  17.         {
  18.             c = a + b;
  19.             a = b;
  20.             b = c;
  21.  
  22.         }
  23.         n -= c;
  24.         ++nrNumere;
  25.     }
  26.     printf("Se poate scrie ca %d numere din sirul lui fibonacci\n", nrNumere);
  27.    
  28.  
  29.     return 0;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement