/*--------------------------------------------------------------------*/ /* sumarray.c */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #include /*--------------------------------------------------------------------*/ enum {ARRAY_LENGTH = 100}; static int aiNumbers[ARRAY_LENGTH]; /* Bad style. */ static int iIndex; /* Bad style. */ static int iCount; /* Bad style. */ static int iSum; /* Bad style. */ /*--------------------------------------------------------------------*/ /* Read up to ARRAY_LENGTH integers from stdin, and write to stdout the sum of those integers. Return 0. */ int main(void) { printf("How many integers? "); scanf("%d", &iCount); /* Should validate. */ for (iIndex = 0; iIndex < iCount; iIndex++) scanf("%d", &aiNumbers[iIndex]); /* Should validate. */ iSum = 0; for (iIndex = 0; iIndex < iCount; iIndex++) iSum += aiNumbers[iIndex]; printf("The sum is %d.\n", iSum); return 0; }