Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. typedef struct kartezjanskie
  6. {
  7.     double x;
  8.     double y;
  9. }kart;
  10.  
  11. typedef struct biegunowe
  12. {
  13.     double r;
  14.     double f;
  15. }bieg;
  16.  
  17. int wybor()
  18. {
  19.     int rodzaj;
  20.     printf("Chcesz wprowadzic wsp kartezjanskie i zamienic na wsp biegunowe, jesli tak nacisnij 1\n");
  21.     printf("Chcesz wprowadzic wsp biegunowe i zamienic na wsp kartezjanskie, jesli tak nacisnij 2\n");
  22.     scanf("%d", &rodzaj);
  23.  
  24.     return rodzaj;
  25. }
  26. void wpisywanie(kart* s,bieg* b,int rodzaj)
  27. {
  28.     if(rodzaj == 1)
  29.     {
  30.         printf("Podaj X");
  31.         scanf("%lf", &s->x);
  32.         printf("Podaj Y");
  33.         scanf("%lf", &s->y);
  34.  
  35.         b->f=atan(s->y/s->x);
  36.         b->r=s->x/cos(b->f);
  37.     }
  38.     else if(rodzaj ==2)
  39.     {
  40.         printf("Podaj R");
  41.         scanf("%lf", &b->r);
  42.         printf("Podaj f");
  43.         scanf("%lf", &b->f);
  44.  
  45.         s->x=b->r*cos(b->f);
  46.         s->y=b->r*sin(b->f);
  47.     }
  48.     else
  49.     {
  50.         printf("Podales zla wartosc operacji\n");
  51.     }
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     kart wsp;
  58.     bieg wsx;
  59.     int rodzaj;
  60.     rodzaj=wybor();
  61.     wpisywanie(&wsp,&wsx,rodzaj);
  62.  
  63.     printf("x=%lf y=%lf f=%lf r=%lf",wsp.x,wsp.y,wsx.r,wsx.f);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement