/*--------------------------------------------------------------------*/ /* sumarrayflat.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. */ iIndex = 0; loop1: if (iIndex >= iCount) goto loopend1; scanf("%d", &aiNumbers[iIndex]); /* Should validate. */ iIndex++; goto loop1; loopend1: iSum = 0; iIndex = 0; loop2: if (iIndex >= iCount) goto loopend2; iSum += aiNumbers[iIndex]; iIndex++; goto loop2; loopend2: printf("The sum is %d.\n", iSum); return 0; }