fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. double a = 0.5; // First term
  6. double r = 0.2; // Common ratio
  7. int n = 100; // Number of terms
  8.  
  9. printf("The first %d terms of the geometric series are:\n", n);
  10.  
  11. for (int i = 0; i < n; i++) {
  12. double term = a * pow(r, i);
  13. printf("Term %d: %.10f\n", i + 1, term);
  14. }
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
The first 100 terms of the geometric series are:
Term 1: 0.5000000000
Term 2: 0.1000000000
Term 3: 0.0200000000
Term 4: 0.0040000000
Term 5: 0.0008000000
Term 6: 0.0001600000
Term 7: 0.0000320000
Term 8: 0.0000064000
Term 9: 0.0000012800
Term 10: 0.0000002560
Term 11: 0.0000000512
Term 12: 0.0000000102
Term 13: 0.0000000020
Term 14: 0.0000000004
Term 15: 0.0000000001
Term 16: 0.0000000000
Term 17: 0.0000000000
Term 18: 0.0000000000
Term 19: 0.0000000000
Term 20: 0.0000000000
Term 21: 0.0000000000
Term 22: 0.0000000000
Term 23: 0.0000000000
Term 24: 0.0000000000
Term 25: 0.0000000000
Term 26: 0.0000000000
Term 27: 0.0000000000
Term 28: 0.0000000000
Term 29: 0.0000000000
Term 30: 0.0000000000
Term 31: 0.0000000000
Term 32: 0.0000000000
Term 33: 0.0000000000
Term 34: 0.0000000000
Term 35: 0.0000000000
Term 36: 0.0000000000
Term 37: 0.0000000000
Term 38: 0.0000000000
Term 39: 0.0000000000
Term 40: 0.0000000000
Term 41: 0.0000000000
Term 42: 0.0000000000
Term 43: 0.0000000000
Term 44: 0.0000000000
Term 45: 0.0000000000
Term 46: 0.0000000000
Term 47: 0.0000000000
Term 48: 0.0000000000
Term 49: 0.0000000000
Term 50: 0.0000000000
Term 51: 0.0000000000
Term 52: 0.0000000000
Term 53: 0.0000000000
Term 54: 0.0000000000
Term 55: 0.0000000000
Term 56: 0.0000000000
Term 57: 0.0000000000
Term 58: 0.0000000000
Term 59: 0.0000000000
Term 60: 0.0000000000
Term 61: 0.0000000000
Term 62: 0.0000000000
Term 63: 0.0000000000
Term 64: 0.0000000000
Term 65: 0.0000000000
Term 66: 0.0000000000
Term 67: 0.0000000000
Term 68: 0.0000000000
Term 69: 0.0000000000
Term 70: 0.0000000000
Term 71: 0.0000000000
Term 72: 0.0000000000
Term 73: 0.0000000000
Term 74: 0.0000000000
Term 75: 0.0000000000
Term 76: 0.0000000000
Term 77: 0.0000000000
Term 78: 0.0000000000
Term 79: 0.0000000000
Term 80: 0.0000000000
Term 81: 0.0000000000
Term 82: 0.0000000000
Term 83: 0.0000000000
Term 84: 0.0000000000
Term 85: 0.0000000000
Term 86: 0.0000000000
Term 87: 0.0000000000
Term 88: 0.0000000000
Term 89: 0.0000000000
Term 90: 0.0000000000
Term 91: 0.0000000000
Term 92: 0.0000000000
Term 93: 0.0000000000
Term 94: 0.0000000000
Term 95: 0.0000000000
Term 96: 0.0000000000
Term 97: 0.0000000000
Term 98: 0.0000000000
Term 99: 0.0000000000
Term 100: 0.0000000000