9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia03/ex29.c (408B)
   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 
   4 #define MAX_LEN 20
   5 
   6 int main (void) {
   7 
   8     int i, suma, vector[MAX_LEN], vector_end;
   9     char buffer[MAX_LEN];
  10 
  11     vector_end = MAX_LEN;
  12     for(i = 0, suma = 0; i < vector_end; i++) {
  13         if(fgets(buffer, sizeof(int) + 1, stdin) != NULL) {
  14             vector[i] = atoi(buffer);
  15             suma += vector[i];
  16         } else {
  17             vector_end = i;
  18             i = MAX_LEN;
  19         }
  20     }
  21     printf("%d\n", suma);
  22     return 0;
  23 }