Edgu

Untitled

Dec 3rd, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <cmath>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. // Čia parašykite funkcijų antraštes
  11. bool ArTrikampis(int a, int b, int c);
  12. bool ArIvairiakrastis(int a, int b, int c);
  13. double TrikampioPlotas(int a, int b, int c);
  14.  
  15. int main()
  16. {
  17.     ofstream rezultatai("Rezultatai4.txt");
  18.  
  19.     int a, b;
  20.     cout << "Iveskite intervalo pirmaji skaiciu" << endl;
  21.     cin >> a;
  22.     cout << "Iveskite intervalo antraji skaiciu" << endl;
  23.     cin >> b;
  24.     vector<double> plotai;
  25.  
  26.     for (int x = a; x <= b; x++)
  27.     {
  28.         for (int y = a; y <= b; y++)
  29.         {
  30.             for (int z = a; z <= b; z++)
  31.             {
  32.                 if (ArTrikampis(x, y, z) && ArIvairiakrastis(x, y, z))
  33.                 {
  34.                     if (find(plotai.begin(), plotai.end(), TrikampioPlotas(x, y, z))!= plotai.end())
  35.                         continue;
  36.                     rezultatai << fixed << setprecision(2) << x << " " << y << " " << z << " " << TrikampioPlotas(x, y, z) << endl;
  37.                     plotai.push_back(TrikampioPlotas(x, y, z));
  38.                 }
  39.             }
  40.         }
  41.     }
  42.     return 0;
  43. }
  44.  
  45. // Funkcija, patikrinanti, ar galima sudaryti trikampį
  46. // Funkcija grąžina reikšmę true, jei trikampį sudaryti galima, priešingu atveju – false;
  47. bool ArTrikampis(int a, int b, int c)
  48. {
  49.     return ((a + b > c) && (a + c > b) && (b + c > a));
  50. }
  51.  
  52. // Funkcija, patikrinanti, ar trikampis įvairiakraštis
  53. // Funkcija grąžina reikšmę true, jei trikampis įvairiakraštis, priešingu atveju – false
  54. bool ArIvairiakrastis(int a, int b, int c)
  55. {
  56.     return ((a != b) && (b != c) && (c != a));
  57. }
  58.  
  59. // Funkcija, grąžinanti apskaičiuotą trikampio plotą.
  60. double TrikampioPlotas(int a, int b, int c)
  61. {
  62.     double s = (a + b + c) / 2.0;
  63.     return sqrt(s * (s - a) * (s - b) * (s - c));
  64. }
Advertisement
Add Comment
Please, Sign In to add comment