Guest User

Untitled

a guest
Apr 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.  
  8. FILE *plik;
  9. FILE*plik2;
  10. plik=fopen("dane.txt","rt");
  11. plik2=fopen("wynik.txt","wt");
  12. float srednia=0, suma=0, x; int d, ilosc, elementy_zbioru=0;
  13.  
  14. printf("podaj wartosc [d]\n");
  15. scanf("%d",&d);
  16.  
  17. if(plik)
  18. {
  19.  
  20. do
  21. {
  22. fscanf(plik,"%f",&x);
  23. suma=x+suma;
  24. ilosc++;
  25.  
  26. }while(!feof(plik));
  27. srednia=suma/ilosc;
  28.  
  29. // ilosc liczb z przedzialu <srednia-d , srednia+d >
  30.  
  31. do
  32. {
  33. elementy_zbioru++;
  34.  
  35. }while ( (x>(srednia-d)) && (x< (srednia+d)) );
  36. }
  37. else (" bledna operacja\n");
  38.  
  39. printf("w przedziale <srednia-d, srednia+d> znajduje sie [%d] elementow\n\n",elementy_zbioru);
  40. fprintf(plik2,"srednia wynosi [%f]\nw zbiorze <srednia-d, srednia+d> znajduje sie %d elementow\nsuma wynosi %f\n",srednia,elementy_zbioru,suma);
  41.  
  42. fclose(plik);
  43. fclose(plik2);
  44.  
  45. system("pause");
  46. }
Add Comment
Please, Sign In to add comment