Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. float suma(float tab[], int a, int b){
  3.  
  4. float s=0;
  5. for(;a<b;a++)
  6. s=s+tab[a];
  7. return s;
  8. }
  9.  
  10.  
  11. int main(){
  12. FILE*we;
  13. int n=0,dane[100];
  14.  
  15. we=fopen("dane.txt","r");
  16.  
  17. if(we){
  18. int x;
  19. int y;
  20. int i,n=0;
  21. while(!feof(we))
  22. fscanf(we,"%d",&dane[n++]);
  23. fclose(we);
  24.  
  25. printf("oto liczby z pliku: \n");
  26. for(i=1;i<=n;i++){
  27. printf("%d ",dane[i-1]);
  28. }
  29. printf("\nsuma tych liczb wynosi: %d \n",suma(dane, 0, n));
  30.  
  31.  
  32. }
  33. else printf("nie moge otworzyc pliku");
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement