Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- void main()
- {
- float slope, intercept;
- float x1, y1, x2, y2;
- float dx, dy;
- std::cout << "Program f\x94r att kalkylera ekvationen av linje\n";
- std::cout << "Skriv X1: ";
- std::cin >> x1;
- std::cout << "Skriv Y1: ";
- std::cin >> y1;
- std::cout << "Skriv X2: ";
- std::cin >> x2;
- std::cout << "Skriv Y2: ";
- std::cin >> y2;
- dx = x2 - x1;
- dy = y2 - y1;
- slope = dy / dx;
- // y = mx + c
- // intercept c = y - mx
- intercept = y1 - slope * x1; // detsamma som y2 - slope * x2
- std::cout << "Ekvation av linje med slutpunkter (" << x1 << ", " << y1 << ") and (" << x2 << ", " << y2 << ") : Y = ";
- std::cout << slope << "X " << ((intercept < 0) ? ' ' : '+') << intercept << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment