المطلوب
أكتب برنامج يطلب من المستخدم إدخال رقمين, ثم يعرض له من هو العدد الأكبر بينهما, و في حال كانا متساويان سيعرض له أنهما كذلك.
مثال: إذا قام المستخدم بإدخال الرقمين 3 و 8 فستكون النتيجة كالتالي.
Enter first number: 3 Enter second number: 8 The biggest number is '8'
الحل بلغة C#
الطريقة الأولى لحل التمرين.
using System;
class Program
{
static void Main(string[] args)
{
int a, b, c, minimum;
Console.Write("Enter a: ");
a = Int32.Parse(Console.ReadLine());
Console.Write("Enter b: ");
b = Int32.Parse(Console.ReadLine());
Console.Write("Enter c: ");
c = Int32.Parse(Console.ReadLine());
minimum = (a < b) ? a : b;
minimum = (minimum < c) ? minimum : c;
Console.WriteLine("The min number is: " + minimum);
Console.ReadKey();
}
}
الطريقة الثانية لحل التمرين و الحصول على نفس النتيجة.
using System;
class Program
{
static void Main(string[] args)
{
int a, b, c, minimum;
Console.Write("Enter a: ");
a = Int32.Parse(Console.ReadLine());
Console.Write("Enter b: ");
b = Int32.Parse(Console.ReadLine());
Console.Write("Enter c: ");
c = Int32.Parse(Console.ReadLine());
if (a < b && a < c)
{
minimum = a;
}
else if (b < a && b < c)
{
minimum = b;
}
else
{
minimum = c;
}
Console.WriteLine("The min number is: " + minimum);
Console.ReadKey();
}
}
الطريقة الثالث لحل التمرين و الحصول على نفس النتيجة.
using System;
class Program
{
static void Main(string[] args)
{
int a, b, c, minimum;
Console.Write("Enter a: ");
a = Int32.Parse(Console.ReadLine());
Console.Write("Enter b: ");
b = Int32.Parse(Console.ReadLine());
Console.Write("Enter c: ");
c = Int32.Parse(Console.ReadLine());
if (a < b && a < c)
{
minimum = a;
}
else
{
minimum = b;
}
if (minimum > c)
{
minimum = c;
}
Console.WriteLine("The min number is: " + minimum);
Console.ReadKey();
}
}
سنحصل على النتيجة التالية إذا قام المستخدم بإدخال الأرقام 2, 7 و 5 عند التشغيل.
Enter a: 2 Enter b: 7 Enter c: 5 The min number is: 2


محرر الويب
نظام الألوان
محول الوحدات
محلل عناوين الشبكات