Advertisement
Guest User

lab3zad1

a guest
Feb 1st, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  lab3.zad1
  4. //
  5. //  Created by Kondziu on 01.02.2015.
  6. //  Copyright (c) 2015 KonradPazgan. All rights reserved.
  7. //
  8.  
  9. //w pliku binarny zapisano 100 liczb calkowyitych, napisac program, ktory czyta ten plik i czyta srednia tych liczb ktore sa wieksze od 100.
  10.  
  11.  
  12. #include <stdio.h>
  13.  
  14. int main(int argc, const char * argv[]) {
  15.    
  16.     int tablica[100];
  17.     FILE* fbinar;
  18.     float suma;
  19.     float srednia;
  20.     int licznik;
  21.    
  22.     suma = 0;
  23.     srednia = 0;
  24.     licznik = 0;
  25.    
  26.     fbinar = fopen("plikbin", "rb");
  27.     fread(tablica, sizeof(int), 100, fbinar);
  28.     fclose(fbinar);
  29.    
  30.     for(int i=0; i<100; i++) {
  31.         if(tablica[i]>100) {
  32.             suma = suma + tablica[i];
  33.             licznik++;
  34.         }
  35.     }
  36.    
  37.     srednia = suma / licznik;
  38.    
  39.     printf("Srednia wynosi %f", srednia);
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement