Advertisement
Guest User

Untitled

a guest
May 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. //Zadanie z trójkątem moim sposobem
  2. //Patryk Ledzion
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. float bok(float x1, float y1, float x2, float y2, char bok)
  10. {
  11.     float dx,dy,p;
  12.     dx = abs(x2-x1);
  13.     dy = abs(y2-y1);
  14.     p = pow(dx,2) + pow(dy,2);
  15.     cout<<endl<<x1<<" "<<x2<<" "<<sqrt(p)<<endl;
  16.     return sqrt(p);
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22.     float p,o,po;
  23.     int ip;
  24.     float x[3];
  25.     float y[3];
  26.     char boki[3] = {'a','b','c'};
  27.     float boki1[3];
  28.     cout << "\nPodaj wspolrzedna x1: ";
  29.     cin>>x[0];
  30.     cout << "\nPodaj wspolrzedna y1: ";
  31.     cin>>y[0];
  32.     cout << "\nPodaj wspolrzedna x2: ";
  33.     cin>>x[1];
  34.     cout << "\nPodaj wspolrzedna y2: ";
  35.     cin>>y[1];
  36.     cout << "\nPodaj wspolrzedna x3: ";
  37.     cin>>x[2];
  38.     cout << "\nPodaj wspolrzedna y3: ";
  39.     cin>>y[2];
  40.  
  41.     for(int i=0;i<3;i++)
  42.     {
  43.         if(i<2)ip = i+1;
  44.         if(i==2)ip= 0;
  45.         boki1[i] = bok(x[i],y[i],x[ip],y[ip],boki[i]);
  46.     }
  47.  
  48.     if((boki1[0]+boki1[1]<=boki1[2]) || (boki1[1]+boki1[2]<=boki1[0]) || (boki1[0]+boki1[2]<=boki1[1]))
  49.     {
  50.         cout<<"Nie da sie z tego zrobic trojkata";
  51.     }else{
  52.         o = boki1[0]+boki1[1]+boki1[2];
  53.         po = o/2;
  54.         p = sqrt(po*(po-boki1[0])*(po-boki1[1])*(po-boki1[2]));
  55.         cout<<"Obwod = "<<o<<endl<<"Pole = "<<p;
  56.     }
  57.  
  58.  
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement