Advertisement
arthur393

Fibonacci

Apr 24th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. int sum_alg(int x) {
  3.     int sum=0, y;
  4.     while (x>0){
  5.          y = x % 10;
  6.          x/=10;
  7.         sum+=y;
  8.     }
  9.     return sum;
  10. }
  11. int main()  {
  12.     int A=0, B=1, C, N, SUM=0;
  13.     scanf ("%d", &N) ;
  14.     while(N) {
  15.          C=A+B;
  16.          B=A;
  17.          A=C;
  18.         if (C%2==0){
  19.              N--;
  20.             SUM+=C;
  21.         }
  22.         printf("%d ",C);
  23.     }
  24.     printf("\n%d %d", SUM, sum_alg(SUM));
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement