Advertisement
weldisalves

Lista 03 - exercício 24

Jun 13th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* 24. Exiba os n primeiros termos da seqüência de
  4. Tribonacci (soma dos três anteriores).
  5. Esta sequência inicia com 1,1 e 2. */
  6.  
  7. int main()
  8. {
  9.     int n,i,a,b,c,tribonacci;
  10.  
  11.     a=1;
  12.     b=1;
  13.     c=2;
  14.  
  15.     printf("\n Digite o valor de n: ");
  16.     scanf("%d",&n);
  17.  
  18.     if(n==1)printf("\n %d",a);
  19.     else if(n==2)printf("\n %d \n %d",a,b);
  20.     else if(n==3)printf("\n %d \n %d \n %d",a,b,c);
  21.     else{
  22.         printf("\n %d \n %d \n %d",a,b,c);
  23.  
  24.         for(i=0;i<n-3;i++)
  25.         {
  26.             tribonacci = a+b+c;
  27.             a = b;
  28.             b = c;
  29.             c = tribonacci;
  30.  
  31.             printf("\n %d",tribonacci);
  32.         }
  33.     }
  34.  
  35.  
  36.     getch();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement