這是老師出的題目
這題在讀取一個三角形的三邊長後,算出三角形面積。
輸入:每個問題輸入分三行,一行一個大於零的整數,當第一個數字為 0 時,表示問題結束。
輸出:面積值,精確到小數點後三位。
範例:
Input:
1
1
1
3
4
5
0
Output:
0.433
6.000
程式要怎樣寫可以讓他三個一組 然後出入0他就停止
小弟功力不才只能寫到
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str1, str2, str3;
str1 = Console.ReadLine();;
str2 = Console.ReadLine();
str3 = Console.ReadLine();
double x, y, z, ans1, total, answer;
x = Convert.ToInt16(str1);
y = Convert.ToInt16(str2);
z = Convert.ToInt16(str3);
ans1 = ((x + y + z) / 2);
total = ans1 * (ans1 - x) * (ans1 - y) * (ans1 - z);
answer = Math.Sqrt(total);
Console.WriteLine(ans1);
Console.WriteLine(total);
Console.WriteLine("{0:F3}", answer);
Console.ReadLine();
}
}
}
希望各位程式神人可以指教指教