/** * Program to sum integers using array (example of while and for loops). * (We don't need an array to solve this problem; it's used only to * illustrate using an array.) */ #include #define ARRAY_SIZE 10 int main(void) { int input; int sum = 0; int num[ARRAY_SIZE]; int count = 0; printf("enter some integers (at most %d values), anything else to stop\n", ARRAY_SIZE); /* WARNING! no safety check here for too much input */ while (scanf("%d", &input) == 1) { num[count++] = input; } for (int i = 0; i < count; ++i) { sum += num[i]; } printf("sum is %d\n", sum); return 0; }