Advertisement
iocoder

seq3.c

Sep 4th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int fact[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
  5.  
  6. int main() {
  7.     int i, n, l;
  8.     int *output;
  9.  
  10.     printf("Enter first number: ");
  11.     scanf("%d",&n);
  12.     printf("Enter sequence length: ");
  13.     scanf("%d",&l);
  14.     output = malloc(sizeof(int)*l);
  15.  
  16.     for (i = 0; i < l; i++){
  17.         int tmp = n;
  18.         int sum = 0;
  19.         do sum += fact[tmp%10]; while (tmp/=10);
  20.         output[i] = n = sum;
  21.     }
  22.  
  23.     for (i = 0; i < l; i++)
  24.         printf("%d:%d\n", i, output[i]);
  25.  
  26.     free(output);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement