找回密碼
 註冊

C語言直線方程式 請幫忙

来源: 新聞 qazsx2349 2010-10-18 11:15 只看這個作者 |閱讀模式
5 7071
題目:
((1))
Read three points.
((2))
Calculate the line equations formed by these three points in the form of ax + by = c.
((3))
Check if the three points can form a triangle. If so, calculate the area of the triangle formed by these three points.
((4))
Enter a point and check which line is nearest the point and its distance.
提示
((1))
The line equation passing two points (a, b) and (c, d) is (b - d)x + (c - a)y = a(b - d) + b(c - a).
((2))
The distance between two points (x1, y1) and (x2, y2) is √(x2 - x1)(x2 - x1) + (y2 - y1)(y2 - y1).
((3))
The distance from a point (m, n) to a line ax + by = c is: |am + bn - c|/√a * a + b * b
((4))
The area of a triangle whose three sides are a, b, and c is √s(s - a)(s - b)(s - c) where s = (a + b + c)/2.
((5))
sqrt is a function for square root calculation. For example, a = sqrt(4.00).
((6))
fabs is a function for the absolute value calculation. For example, a = fabs(-2.00).
我只寫出第二題的一條方程式
因為有三個點座標 所以應該有三條線
可是我不知道怎麼寫 有車友可以幫忙嗎
三四題不會寫...
我們現在是用最簡單的C語言在寫
只教到IF 和WHILE 和迴圈
本文最後由 阿冰 於 2017-9-28 15:20 編輯

收藏
收藏0

網友回覆5

跳到指定樓層
2#
lighthead 2010-10-18 11:42 只看這個作者
3可以用 [兩邊長要大於第三邊]  就可以判斷可不可以形成三角形了
4也是用距離公式就可以了....我記得叫[點到直線距離公式]
本文最後由 阿冰 於 2017-9-28 15:21 編輯

3#
qazsx2349 2010-10-18 13:11 只看這個作者
3可以用 [兩邊長要大於第三邊]  就可以判斷可不可以形成三角形了
4也是用距離公式就可以了....我記得叫[點到直線距離公式] [/quote]
這些我知道呀190.gif
可是要寫成C語言 就不會了107.gif
整個好困難  要宣告 還要一堆什麼的
有人可以幫忙嗎

本文最後由 阿冰 於 2017-9-28 15:21 編輯

4#
lethol 2010-10-18 13:48 只看這個作者
第三題是用海龍公式即可算出面積
(提示4 為海龍公式)
第四題提示已經有給點到線的公式了
兩題的平方根用題目給的sqrt來算就可以

本文最後由 阿冰 於 2017-9-28 15:21 編輯

5#
qazsx2349 2010-10-18 15:30 只看這個作者
第三題是用海龍公式即可算出面積
(提示4 為海龍公式)
第四題提示已經有給點到線的公式了
兩題的平方根用題目給的sqrt來算就可以 [/quote]
先謝謝大大101.gif
這些我都知道阿 高中都有學過
可是要寫成"C語言"就不會了
要宣告一些數字什麼的...真的很難068.gif

本文最後由 阿冰 於 2017-9-28 15:21 編輯


  1. /*這是個小作業
  2.    求出點跟點之間的距離     還有 我用dev c  */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. void distance(double,x1,x2,y1,y2);
  7. int main(int argc, char *argv[])
  8. {   
  9.     double x1;
  10.     double x2;
  11.     double y1;
  12.     double y2;
  13.     printf("請輸入(x1,x2)");
  14.     scanf("%1f ", &x1);
  15.     scanf("%1f",&x2);
  16.     printf("請輸入(y1,y2)");
  17.     scanf("%1f", &y1);
  18.     scanf("%1f", &y2);

  19.     distance(x1, x2, y1, y2);
  20.      
  21.   
  22.   system("PAUSE");       
  23.   return 0;
  24. }
  25. void distance(double ,x1, x2, y1, y2)
  26. {   double ln;
  27.     double x1;
  28.     double x2;
  29.     double y1;
  30.     double y2;
  31.     double distance;
  32.      
  33. ln=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
  34.    
  35. printf("%1f",pow(ln,0.5) );

  36. }
複製代碼
給你參考一下吧 084.gif
小弟是個不才的資工系學生  只能給你一些小提示 105.gif