Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6. double x;
  7. double y;
  8. double R1;
  9. double R2;
  10. printf("Program prosi o podanie wspolrzednych punktu (x,y),");
  11. printf("\na nastepnie oblicza odleglosc punktu od poczatku ukladu wspolrzednych,\n");
  12. printf("liczy ja na dwa sposoby i porownuje wyniki.\n\n");
  13. printf("Autor programu: Sara Matczak\n\n");
  14. //wczytywanie danych
  15. printf("Podaj x (liczbe zmiennopozycyjna w systemie dziesietnym): ");
  16. if (scanf("%lf",&x)!=1 || getchar()!='\n')
  17. {
  18. printf("Bledne dane.\n");
  19. printf("\nKoniec programu.\n");
  20. return 0;
  21. }
  22. printf("Podales argument x = %.15g.\n",x);
  23. printf("Podaj y (liczbe zmiennopozycyjna w systemie dziesietnym):\n");
  24. if (scanf("%lf",&y)!=1 || getchar()!='\n')
  25. {
  26. printf("Bledne dane.\n");
  27. printf("\nKoniec programu.\n");
  28. return 0;
  29. }
  30. printf("Podales argument x = %.15g.\n",y);
  31. R1=sqrt(x*x+y*y);
  32. printf("Odleglosc liczona wg klasycznego wzoru:%lf\n",R1);
  33. if(x=0)
  34. {
  35. R2=fabs(y);
  36. printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
  37. }
  38. else if (fabs(x)>=fabs(y) && x!=0)
  39. {
  40. R2=fabs(x)*sqrt(1+pow(x/y,2));
  41. printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
  42.  
  43. }
  44. else
  45. {
  46. R2=fabs(y)*sqrt(1+pow(x/y,2));
  47. printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
  48. }
  49. if (R1==R2)
  50. {
  51. printf("OBA ALGORYTMY DAJA TEN SAMY WYNIK.\n");
  52. printf("Odleglosc punktu (3,4)od (0,0)wynosi 5.\n");
  53. }
  54. else
  55. {
  56. printf("ALGORYTMY DAJA ROZNE WYNIKI.\n");
  57. printf("-wg \"klasycznego\" algorytmu 20.09975124224178,\n");
  58. printf("-wg \"speckjalnego\" algorytmu 20.099751249284704.\n\n");
  59. printf("Wartosc bezwzgledna roznicy miedzy wynikami:\n");
  60. printf("\t7.042924465849646e-009.\n");
  61. }
  62.  
  63. printf("\nKoniec programu.\n");
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement