bbanelli
Jul 4th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int paralela(void) {
  5.     FILE *p, *f;
  6.     char otp[200];
  7.     int i;
  8.     float rjesenje, zbroj = 0;
  9.     p = fopen("otpori.txt", "r");
  10.     if (p == NULL) {
  11.         return 0;
  12.     }
  13.     else {
  14.         f = fopen("rezultat.txt", "w+");
  15.         if (f == NULL) {
  16.             return 0;
  17.         }
  18.     }
  19.     while (fscanf(p, "%s", otp) == 1) {
  20.         i = atoi(otp);
  21.         zbroj += 1.0/i;
  22.         //zbroj += (float)1/i;
  23.     }
  24.     rjesenje = 1 / zbroj;
  25.     fprintf(f, "%f", rjesenje);
  26.     fclose(p);
  27.     fclose(f);
  28.     return 1;
  29. }
  30.  
  31. int main(void) {
  32.     if (paralela()) {}
  33.     else printf("greska...");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment