fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int a, r, n;
  5. int s, ai, i;
  6.  
  7. scanf("%d%d%d", &a, &r, &n);
  8.  
  9. ai = a; // i = 1, the first term
  10. s = a;
  11.  
  12. printf("%d ", a);
  13. for (i = 2;i<=n;i++) {
  14. ai = ai*r;
  15. s += ai;
  16. printf("+ %d ",ai);
  17. }
  18.  
  19. printf("= %d\n", s);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5324KB
stdin
2 3 4
stdout
2 + 6 + 18 + 54 = 80