標題: C語言的算法之:求直角三角形邊長。 [打印本頁]

作者: XYDDD    時間: 2022-8-9 14:46
標題: C語言的算法之:求直角三角形邊長。

今天一起分析C語言的算法之13:求直角三角形邊長。

算法題目:

求直角三角形兩個邊長的長度:已知斜邊長度L,求2個直角邊:X,Y長度。



                      1.編程思路分析

編程思路:

調用C語言的庫函數,用sin函數和cos函數計算出直角邊。


                     2.程序范例

#include <stdio.h>

#include <math.h>

void main()

{

  float a,b,R,L,r;

  printf("請輸入斜邊長度:");

  scanf("%f",&L);

  printf("請輸入其中一斜角度數:");

  scanf("%f",&r);

  R=r/180*3.1415926;  //計算弧度

  a=sin(R)*L;  //計算一直角邊

  b=cos(R)*L; //計算另一直角邊

  printf("%.2f\n",a);

  printf("%.2f\n",b);

}

程序運行結果案例:













歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1