Advertisement
nontawat1996

Untitled

Oct 14th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n,i,j,k;
  6.     int num[100];
  7.     while(1)
  8.     {
  9.         scanf("%d",&n);
  10.         if(n==0) return 0;
  11.        
  12.         for(i=0; i<n; i++) scanf("%d",&num[i]);
  13.        
  14.         scanf("%d",&k);
  15.         for (j=n-1; j>0; j--)
  16.         {
  17.             for (i=0; i<j; i++)
  18.             {
  19.                 num[i]=num[i+1]-num[i];
  20.             }
  21.         }
  22.         for (i=0; i<k; i++)
  23.         {
  24.             for (j=1; j<n; j++)
  25.             {
  26.                 num[j]+=num[j-1];
  27.             }
  28.         }
  29.         printf("Term %d of the sequence is %hd\n", n+k, num[n-1]);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement