fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define TABSIZE 5
  4.  
  5. double sum_tab(double tab[], size_t len);
  6. void print_tab(double tab[], size_t len);
  7.  
  8. int main(void) {
  9. double X = 832.232323;
  10. double tab_1[TABSIZE] = {45, 8.324, 9999, 9234932, 843.32};
  11. double tab_2[TABSIZE];
  12.  
  13. double suma = sum_tab(tab_1, TABSIZE);
  14.  
  15. for(size_t i=0;i<TABSIZE;++i) { tab_2[i] = tab_1[i]/suma; }
  16. for(size_t i=0;i<TABSIZE;++i) { tab_2[i] = tab_2[i] * X; }
  17.  
  18. puts("tab_1");
  19. print_tab(tab_1, TABSIZE);
  20. puts("\ntab_2");
  21. print_tab(tab_2, TABSIZE);
  22. puts("");
  23. printf("X = %5.5f\nsuma tablicy = %5.5f\n", X, sum_tab(tab_2, TABSIZE));
  24. return 0;
  25. }
  26.  
  27. double sum_tab(double tab[], size_t len) {
  28. double sum = 0;
  29. for(size_t i=0;i<len;++i) { sum += tab[i]; }
  30. return sum;
  31. }
  32.  
  33. void print_tab(double tab[], size_t len) {
  34. for(size_t i=0;i<len;++i) {
  35. printf("%5.5f ", tab[i]);
  36. if((i%5) == 4) { printf("\n"); }
  37. }
  38. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
tab_1
45.00000 8.32400 9999.00000 9234932.00000 843.32000 

tab_2
0.00405 0.00075 0.90003 831.25159 0.07591 

X = 832.23232
suma tablicy = 832.23232