fork download
  1. //Q57. Find the sum of array elements.
  2. #include <stdio.h>
  3. int main() {
  4. int n, i, sum = 0;
  5. printf("Enter number of elements:\n ");
  6. scanf("%d", &n);
  7.  
  8. int arr[n];
  9. printf("Enter %d elements:\n", n);
  10. for(i = 0; i < n; i++) {
  11. scanf("%d", &arr[i]);
  12. sum += arr[i];
  13. }
  14.  
  15. printf("Sum of array elements = %d", sum);
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5288KB
stdin
4
2 4 6 8
stdout
Enter number of elements:
 Enter 4 elements:
Sum of array elements = 20