fork download
  1. #include <stdio.h>
  2.  
  3. int seq() {
  4. static int current_term = 1;
  5. int result = current_term;
  6. current_term++;
  7.  
  8. return result;
  9. }
  10.  
  11. int main() {
  12. printf("2nd term: %d\n", seq());
  13. printf("3rd term: %d\n", seq());
  14. printf("4th term: %d\n", seq());
  15. printf("5th term: %d\n", seq());
  16. printf("6th term: %d\n", seq());
  17. printf("7th term: %d\n", seq());
  18. printf("8th term: %d\n", seq());
  19. printf("9th term: %d\n", seq());
  20. printf("10th term: %d\n", seq());
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5284KB
stdin
1 2
stdout
2nd term: 1
3rd term: 2
4th term: 3
5th term: 4
6th term: 5
7th term: 6
8th term: 7
9th term: 8
10th term: 9