This series 1 2 3 6 9 18 27 54 has a pattern. The pattern is for odd position it adds up the previous number. For even position it doubles the number. Following is the implementation in C language:
#includeint main() { int sum = 1, last = 0; for(int i = 1; i < 10; i++){ if(i % 2 == 0) { last = sum; sum *=2; } else { sum +=last; } printf("%d ", sum); } return 0; }
Comments
Post a Comment