Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- double x;
- double y;
- double R1;
- double R2;
- printf("Program prosi o podanie wspolrzednych punktu (x,y),");
- printf("\na nastepnie oblicza odleglosc punktu od poczatku ukladu wspolrzednych,\n");
- printf("liczy ja na dwa sposoby i porownuje wyniki.\n\n");
- printf("Autor programu: Sara Matczak\n\n");
- //wczytywanie danych
- printf("Podaj x (liczbe zmiennopozycyjna w systemie dziesietnym): ");
- if (scanf("%lf",&x)!=1 || getchar()!='\n')
- {
- printf("Bledne dane.\n");
- printf("\nKoniec programu.\n");
- return 0;
- }
- printf("Podales argument x = %.15g.\n",x);
- printf("Podaj y (liczbe zmiennopozycyjna w systemie dziesietnym):\n");
- if (scanf("%lf",&y)!=1 || getchar()!='\n')
- {
- printf("Bledne dane.\n");
- printf("\nKoniec programu.\n");
- return 0;
- }
- printf("Podales argument x = %.15g.\n",y);
- R1=sqrt(x*x+y*y);
- printf("Odleglosc liczona wg klasycznego wzoru:%lf\n",R1);
- if(x=0)
- {
- R2=fabs(y);
- printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
- }
- else if (fabs(x)>=fabs(y) && x!=0)
- {
- R2=fabs(x)*sqrt(1+pow(x/y,2));
- printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
- }
- else
- {
- R2=fabs(y)*sqrt(1+pow(x/y,2));
- printf("Odleglosc liczona wg specjalnego wzoru:%lf\n\n",R2);
- }
- if (R1==R2)
- {
- printf("OBA ALGORYTMY DAJA TEN SAMY WYNIK.\n");
- printf("Odleglosc punktu (3,4)od (0,0)wynosi 5.\n");
- }
- else
- {
- printf("ALGORYTMY DAJA ROZNE WYNIKI.\n");
- printf("-wg \"klasycznego\" algorytmu 20.09975124224178,\n");
- printf("-wg \"speckjalnego\" algorytmu 20.099751249284704.\n\n");
- printf("Wartosc bezwzgledna roznicy miedzy wynikami:\n");
- printf("\t7.042924465849646e-009.\n");
- }
- printf("\nKoniec programu.\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement