fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int a[100];
  5. for (int i = 0; i < 100; i++)
  6. a[i] = i;
  7.  
  8. int sum = 0;
  9. int start = 10, end = 40;
  10.  
  11. for (int i = start; i <= end; i++)
  12. sum += a[i];
  13.  
  14. printf("Sum from a[%d] to a[%d] is: %d\n", start, end, sum);
  15. printf("Average from a[%d] to a[%d] is: %g\n", start, end, (float)(sum) / (float)(end - start + 1));
  16.  
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Sum from a[10] to a[40] is: 775
Average from a[10] to a[40] is: 25