在 PL/SQL 中求直角三角形的面積和周長
在這個問題中,我們給定一個直角三角形的三個值:底邊、高和斜邊。我們的任務是在 PL/SQL 中求直角三角形的面積和周長。
PL/SQL將 SQL 與程式語言的過程化特性相結合
我們舉個例子來理解這個問題,
Input : height = 4, base = 3, hypotenuse = 5 Output : area = 6, perimeter = 12
說明 −
1 + 22 + 333 + 4444 = 4800
求解方法
解決該問題的簡單方法是使用三角形的面積和周長的公式。
面積 = 1/2*(高)*(底邊)
周長 = (高) + (底邊) + (斜邊)
示例
程式來說明 PL/SQL 中我們解決方案的工作原理
DECLARE hypotenuse FLOAT; base FLOAT; height FLOAT; area FLOAT; perimeter FLOAT; BEGIN hypotenuse := 13; base := 5; height := 12; area := (1/2)* base * height; perimeter := hypotenuse + height + base; dbms_output.Put_line('The Perimeter of triangle is ' || perimeter); dbms_output.Put_line('The Area of triangle is ' || area); END;
輸出
The Perimeter of triangle is 30 The area of triangle is 30
廣告