โค้ดคำนวณผลคูณโดยป้อนจำนวนครั้งที่จะคูณ(ไม่วนloop)
int count = 0, N;
double result = 1;
int num;
Console.Write("How many number number to multiply:");
N = int.Parse(Console.ReadLine());
while (N > count)
{
Console.Write("Input interger number no.{0}:>", count + 1);
num = int.Parse(Console.ReadLine());
count++;
result *= num;
}
Console.WriteLine("The answer is{0}",result); Code (C#)
Date :
2010-02-08 23:04:47
By :
DYonceKoyDiiZZaS
No. 5
Guest
โค้ดคำนวณพื้นที่วงกลม,สามเหลี่ยมแบบมีตัวเลือก(วนloop)
float PI = 3.14f;
float R, Area;
float Base = 0, Height = 0;
int Choice;
do{
Console.WriteLine("Press select to choice");
Console.WriteLine("1.Circle");
Console.WriteLine("2.Triangle");
Console.WriteLine("3.Exit");
Console.Write("Please select your choice:");
Choice = int.Parse(Console.ReadLine());
switch (Choice)
{
case 1:
Console.Write("Input R:>");
R = float.Parse(Console.ReadLine());
Area = PI * R * R;
Console.WriteLine("The area is {0}", Area);
break;
case 2:
Console.Write("Input base:>");
Base = float.Parse(Console.ReadLine());
Console.Write("Input height:>");
Height = float.Parse(Console.ReadLine());
Area = 0.5f * Base * Height;
Console.WriteLine("The area is {0}", Area);
break;
}
} while (Choice != 3); Code (C#)