Advertisement
syaghi

C for loop sum

Dec 3rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  5.     int sum = 0;
  6.     int i;
  7.    
  8.     for (i = 0; i < 10; i++) {
  9.         sum += array[i];
  10.     }
  11.    
  12.     /* sum now contains a[0] + a[1] + ... + a[9] */
  13.     printf("Sum of the array is %d\n", sum);
  14.    
  15.  
  16. return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement