TotteL

Untitled

Sep 18th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. void main()
  5. {
  6.     float slope, intercept;
  7.     float x1, y1, x2, y2;
  8.     float dx, dy;
  9.  
  10.     std::cout << "Program f\x94r att kalkylera ekvationen av linje\n";
  11.  
  12.     std::cout << "Skriv X1: ";
  13.     std::cin >> x1;
  14.  
  15.     std::cout << "Skriv Y1: ";
  16.     std::cin >> y1;
  17.  
  18.     std::cout << "Skriv X2: ";
  19.     std::cin >> x2;
  20.  
  21.     std::cout << "Skriv Y2: ";
  22.     std::cin >> y2;
  23.  
  24.     dx = x2 - x1;
  25.     dy = y2 - y1;
  26.  
  27.     slope = dy / dx;
  28.     // y = mx + c
  29.     // intercept c = y - mx
  30.     intercept = y1 - slope * x1; // detsamma som y2 - slope * x2
  31.  
  32.     std::cout << "Ekvation av linje med slutpunkter (" << x1 << ", " << y1 << ") and (" << x2 << ", " << y2 << ") : Y = ";
  33.     std::cout << slope << "X " << ((intercept < 0) ? ' ' : '+') << intercept << "\n";
  34. }
Advertisement
Add Comment
Please, Sign In to add comment