C Language Example - Calculate the Sum of Array Elements

C Language Examples

Use a for loop to iterate over the output elements and add them together:

Example

#include <stdio.h> int main() { int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int sum, loop; sum = 0; for(loop = 9; loop >= 0; loop--) { sum = sum + array[loop]; } printf("Sum of elements: %d", sum); return 0; }

The output result is:

元素和为:45

C Language Examples

other extensions