Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<math.h>
- int main()
- {
- FILE *plik;
- FILE*plik2;
- plik=fopen("dane.txt","rt");
- plik2=fopen("wynik.txt","wt");
- float srednia=0, suma=0, x; int d, ilosc, elementy_zbioru=0;
- printf("podaj wartosc [d]\n");
- scanf("%d",&d);
- if(plik)
- {
- do
- {
- fscanf(plik,"%f",&x);
- suma=x+suma;
- ilosc++;
- }while(!feof(plik));
- srednia=suma/ilosc;
- // ilosc liczb z przedzialu <srednia-d , srednia+d >
- do
- {
- elementy_zbioru++;
- }while ( (x>(srednia-d)) && (x< (srednia+d)) );
- }
- else (" bledna operacja\n");
- printf("w przedziale <srednia-d, srednia+d> znajduje sie [%d] elementow\n\n",elementy_zbioru);
- fprintf(plik2,"srednia wynosi [%f]\nw zbiorze <srednia-d, srednia+d> znajduje sie %d elementow\nsuma wynosi %f\n",srednia,elementy_zbioru,suma);
- fclose(plik);
- fclose(plik2);
- system("pause");
- }
Add Comment
Please, Sign In to add comment