jazykc  2013.3
upoljazykc
 All Classes Files Functions Variables Typedefs Macros Pages
suma-pole.c
Go to the documentation of this file.
1 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #define NELEM(pole) (sizeof pole/sizeof pole[0])
31 
32 double suma_pole (double pole[], int pocet) {
33  double suma = pole[0];
34  int i;
35  for (i=1; i<pocet; i++) {
36  suma += pole[i];
37  }
38  return suma;
39 }
40 
41 static void pole_vypis(double pole[], size_t pocet) {
42  int i;
43  printf("Pole obsahuje cisla");
44  for (i=0; i<pocet; i++) {
45  printf("%s%g", i ? ", " : ": ", pole[i]);
46  }
47  putchar('\n');
48 }
49 
50 double pole10[10] = {1,2,3,4,5,6,7,8,9,10.10};
51 
52 int main(void) {
53 
54  pole_vypis(pole10, NELEM(pole10));
55  printf("Suma pole je: %g\n", suma_pole(pole10, NELEM(pole10)));
56  return EXIT_SUCCESS;
57 }
#define NELEM(pole)