Advertisement
ebx

Krugovi

ebx
Jun 27th, 2011
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. float duzina(float, float);
  6.  
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. FILE *fp, *ffpp;
  11. int br=0;
  12. float x,y,r;
  13.  
  14. fp=fopen("krugovi.dat", "r");
  15. if (fp==NULL) {
  16. printf("Nem're otvor't citanku!\n");
  17. getchar();
  18. return 0;
  19. }
  20. else {
  21. printf("Utvorio citanku!\n");
  22. ffpp=fopen("rezultat.txt", "w");
  23. if (ffpp==NULL) {
  24. printf("Nem're otvor't pisaljku!\n");
  25. getchar();
  26. return 0;
  27. }
  28. else {
  29. printf("Otvorio pisaljku!\n");
  30. while(!feof(fp)) {
  31. fscanf(fp, "(%f,%f,%f)\n", &x, &y, &r);
  32. if(duzina(x,y)>r)
  33. br++;
  34. }
  35. fprintf(ffpp, "Trazeni broj krugova je: %d\n", br);
  36.  
  37. fflush(ffpp);
  38. rewind(fp);
  39.  
  40. while(!feof(fp)) {
  41. fscanf(fp, "(%f,%f,%f)\n", &x, &y, &r);
  42. if(duzina(x,y)>r)
  43. fprintf(ffpp, "(%.2f,%.2f,%.2f)\n", x, y, r);
  44. }
  45. fclose(fp);
  46. printf("Zatvorio citanku!\n");
  47. }
  48. fclose(ffpp);
  49. printf("Zatvorio pisaljku!\n");
  50. }
  51. getchar();
  52. return 0;
  53. }
  54.  
  55.  
  56. float duzina(float x, float y) {
  57. return (sqrt(x*x + y*y));
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement