إ₰...👨🏻💻CODE👩🏻💻...₰❥
#التحكم_باستخدام try & catch
تخبر #C أن يحاول بالكود المرفق بين أقواس try
فإذا وجد خطأ من النوع المعرف داخل أقواس catch
يقوم بما هو داخل أقواسها
وأخيرا عند الخروج من catch & try سينفذ البرنامج محتويات finally
سواًء كان هناك خطأ أم لم يكن....
#كود تكرار المحاولة لادخال اعداد فقط حتى عدم حصول الخطأ :-
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
int x;
int s = 1;
a:
Console.Write("Enter Number only :");
try
{
x = Convert.ToInt32(Console.ReadLine());
}
catch
{
goto a;
}
finally
{
Console.WriteLine("try " + s);
s += 1;
}
Console.WriteLine("\b Done!");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Number only :N
try 1
Enter Number only :A!!
try 2
Enter Number only :22
Done!
*--*--*--*--*--*--*--*--*--*--*--*--*
بإمكانك استخدام أكثر من catch لرصد أكثر من نوع خطأ
وكذالك بإمكانك أيضا عدم استخدام finally بتاتآ....
#التحكم_باستخدام try & catch
تخبر #C أن يحاول بالكود المرفق بين أقواس try
فإذا وجد خطأ من النوع المعرف داخل أقواس catch
يقوم بما هو داخل أقواسها
وأخيرا عند الخروج من catch & try سينفذ البرنامج محتويات finally
سواًء كان هناك خطأ أم لم يكن....
#كود تكرار المحاولة لادخال اعداد فقط حتى عدم حصول الخطأ :-
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
int x;
int s = 1;
a:
Console.Write("Enter Number only :");
try
{
x = Convert.ToInt32(Console.ReadLine());
}
catch
{
goto a;
}
finally
{
Console.WriteLine("try " + s);
s += 1;
}
Console.WriteLine("\b Done!");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Number only :N
try 1
Enter Number only :A!!
try 2
Enter Number only :22
Done!
*--*--*--*--*--*--*--*--*--*--*--*--*
بإمكانك استخدام أكثر من catch لرصد أكثر من نوع خطأ
وكذالك بإمكانك أيضا عدم استخدام finally بتاتآ....
إ₰...👨🏻💻CODE👩🏻💻...₰❥
كود لتوضيح دوال التعديل على النصوص :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
string s = "COODE";
Console.WriteLine(s.Count());
// Prints 4
//للحصول على عدد أحرف عبارة نصية بأستخدم التابع Count
Console.WriteLine(s.First());
// Prints C
Console.WriteLine(s.Last());
// Prints E
//للحصول على أول وآخر حرف استخدم التابعين First وLast
Console.WriteLine(s.Insert(2,"_C#_"));
// Prints CO_C#_DE
//لأضافة أحرف إلى عبارة نصية باستخدم التابع Insert
Console.WriteLine(s.Length);
// rints 4
//للحصول على طول عبارة نصية باستخدم الخاصية Length
Console.WriteLine(s.ToLower();
// Prints code Console.WriteLine(s.ToUpper());
// Prints CODE
//لتصغير جميع أحرف عبارة نصية أو تكبيرها باستخدم التابعين ToLower & ToUpper
bool b = s.Contains("D");
Console.WriteLine(b);
//True
//لمعرفة إذا كان محتوى المتغير يحوي قيمة نصية معينة
int i = s.IndexOf("O");
Console.WriteLine(i);
//1
//لمعرفة مكان وجود قيمة نصية ضمن قيمة نصية أخرى
string s2 = s.Replace("O", "g");
Console.WriteLine(s2);
//s2 =CggDE
//لاستبدال قيمة نصية ضمن قيمة نصية أخرى
string s3 = s.Replace("C", string.Empty);
Console.WriteLine(s3);
//s3 =OODE
//كما يمكن الاستفادة من الاستبدال وذلك لأزالة قيم نصية محددة ضمن قيمة نصية أخرى
s += " ";
string s4 = s.Trim();
Console.WriteLine(s4);
//s4 =COODE
//لأزالة الفراغات التي لا اهمية لها
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
5
C
E
CO_C#_ODE
5
coode
COODE
True
1
CggDE
OODE
COODE
كود لتوضيح دوال التعديل على النصوص :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
string s = "COODE";
Console.WriteLine(s.Count());
// Prints 4
//للحصول على عدد أحرف عبارة نصية بأستخدم التابع Count
Console.WriteLine(s.First());
// Prints C
Console.WriteLine(s.Last());
// Prints E
//للحصول على أول وآخر حرف استخدم التابعين First وLast
Console.WriteLine(s.Insert(2,"_C#_"));
// Prints CO_C#_DE
//لأضافة أحرف إلى عبارة نصية باستخدم التابع Insert
Console.WriteLine(s.Length);
// rints 4
//للحصول على طول عبارة نصية باستخدم الخاصية Length
Console.WriteLine(s.ToLower();
// Prints code Console.WriteLine(s.ToUpper());
// Prints CODE
//لتصغير جميع أحرف عبارة نصية أو تكبيرها باستخدم التابعين ToLower & ToUpper
bool b = s.Contains("D");
Console.WriteLine(b);
//True
//لمعرفة إذا كان محتوى المتغير يحوي قيمة نصية معينة
int i = s.IndexOf("O");
Console.WriteLine(i);
//1
//لمعرفة مكان وجود قيمة نصية ضمن قيمة نصية أخرى
string s2 = s.Replace("O", "g");
Console.WriteLine(s2);
//s2 =CggDE
//لاستبدال قيمة نصية ضمن قيمة نصية أخرى
string s3 = s.Replace("C", string.Empty);
Console.WriteLine(s3);
//s3 =OODE
//كما يمكن الاستفادة من الاستبدال وذلك لأزالة قيم نصية محددة ضمن قيمة نصية أخرى
s += " ";
string s4 = s.Trim();
Console.WriteLine(s4);
//s4 =COODE
//لأزالة الفراغات التي لا اهمية لها
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
5
C
E
CO_C#_ODE
5
coode
COODE
True
1
CggDE
OODE
COODE
إ₰...👨🏻💻..👩🏻💻...₰❥
تطبيقات Console المبرمجة لأغراض تعليمية أو تجريبية
يستخدم تطبيق Dcoder
حيث يدعم الكثير من اللغات البرمجية التي تتعامل مع بيئة Console.
تطبيق Dcoder....
لا يعمل الا إذا كنت متصل بالأنترنت.
كما أنه يوفر لك إمكانية حفظ مشاريعك وتطبيقاتك.
يدعم تطبيق Dcoder اللغات البرمجية والبيئات التالية:
C , C++ , C# , Java , Python , VB.Net , Pascal , Html , Css
والكثير من اللغات الاخرى.....
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @language_barmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
تطبيقات Console المبرمجة لأغراض تعليمية أو تجريبية
يستخدم تطبيق Dcoder
حيث يدعم الكثير من اللغات البرمجية التي تتعامل مع بيئة Console.
تطبيق Dcoder....
لا يعمل الا إذا كنت متصل بالأنترنت.
كما أنه يوفر لك إمكانية حفظ مشاريعك وتطبيقاتك.
يدعم تطبيق Dcoder اللغات البرمجية والبيئات التالية:
C , C++ , C# , Java , Python , VB.Net , Pascal , Html , Css
والكثير من اللغات الاخرى.....
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @language_barmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...👨🏻💻......👩🏻💻...₰❥
#بعض_خصائص_الكونسول
1⃣ Console.Clear();
يعمل هذا الكود بمسح شاشه الدوس Dos.
2⃣ Console.Beep();
هذا الكود لأصدار صوت من شاشه الدوس.
3⃣ Console.BackgroundColor =ConsoleColor.Blue;
لتغيير لون ما خلف الكلام فى شاشه الدوس....اي تغيير لون النافذة.
4⃣ Console.Tetle =("CODE");
هذا الكود لتغيير عنوان مشروعك الى العبارة داخل التنصيص.
والعنوان الافتراضي لها يكون على اسم المشروع.
5⃣ Consloe.ForegroundColor = ConsoleColor.DarkGreen;
لتغيير لون الخط بشاشة الدوس.
6⃣ Console.SetCursorPosition(10 , 10 );
لتغيير مكان مؤشر البداية.
7⃣ Console.Write ("CODE");
يعمل هذا الكود بطباعة عبارة نصية مع إبقاء مؤشر الكتابة على السطر نفسه.
8⃣ Console.WriteLine("Wasam Code");
للكتابه فى سطر مستقل لايمكن الكتابه فية مره اخرى...اي للانتقال للسطر التالي.
9⃣int CODE= int.parse(Console.ReadLine());
هذا الكود لكى يقرأ الكونسول قيمة عددية
ادخله المستخدم بشاشة الدوس .
🔟 string CODE=Console.ReadLine();
هذا الكود لكى يقرأ الكونسول نص ما ادخله المستخدم بشاشة الدوس.
1⃣ Console.ReadKey();
ٌهذا الكود يعمل بتثبيت شاشه الدوس وعدم اغالقها تلقائيا الا عند الضغط على اى زر من الكيبورد.
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
#بعض_خصائص_الكونسول
1⃣ Console.Clear();
يعمل هذا الكود بمسح شاشه الدوس Dos.
2⃣ Console.Beep();
هذا الكود لأصدار صوت من شاشه الدوس.
3⃣ Console.BackgroundColor =ConsoleColor.Blue;
لتغيير لون ما خلف الكلام فى شاشه الدوس....اي تغيير لون النافذة.
4⃣ Console.Tetle =("CODE");
هذا الكود لتغيير عنوان مشروعك الى العبارة داخل التنصيص.
والعنوان الافتراضي لها يكون على اسم المشروع.
5⃣ Consloe.ForegroundColor = ConsoleColor.DarkGreen;
لتغيير لون الخط بشاشة الدوس.
6⃣ Console.SetCursorPosition(10 , 10 );
لتغيير مكان مؤشر البداية.
7⃣ Console.Write ("CODE");
يعمل هذا الكود بطباعة عبارة نصية مع إبقاء مؤشر الكتابة على السطر نفسه.
8⃣ Console.WriteLine("Wasam Code");
للكتابه فى سطر مستقل لايمكن الكتابه فية مره اخرى...اي للانتقال للسطر التالي.
9⃣int CODE= int.parse(Console.ReadLine());
هذا الكود لكى يقرأ الكونسول قيمة عددية
ادخله المستخدم بشاشة الدوس .
🔟 string CODE=Console.ReadLine();
هذا الكود لكى يقرأ الكونسول نص ما ادخله المستخدم بشاشة الدوس.
1⃣ Console.ReadKey();
ٌهذا الكود يعمل بتثبيت شاشه الدوس وعدم اغالقها تلقائيا الا عند الضغط على اى زر من الكيبورد.
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...👨🏻💻..👩🏻💻...₰❥
يمكن الحصول على نسخة تنفيذية exe من البرنامج....
وذلك بالانتقال إلى موقع المشروع ثم مجلد bin ثم Debug
ستجد بعض الملفات ومنها الملف التنفيذي المطلوب...👍🏻
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @language_barmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
يمكن الحصول على نسخة تنفيذية exe من البرنامج....
وذلك بالانتقال إلى موقع المشروع ثم مجلد bin ثم Debug
ستجد بعض الملفات ومنها الملف التنفيذي المطلوب...👍🏻
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @language_barmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...👨🏻💻CODE👩🏻💻...₰❥
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
string a = "hello";
string b = "h";
b += "ello";
Console.WriteLine(a == b);
Console.WriteLine((object)a == (object)b);
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
string a = "hello";
string b = "h";
b += "ello";
Console.WriteLine(a == b);
Console.WriteLine((object)a == (object)b);
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
#الاجابة_الصحيحة .....
True
False
لأن محتوى كلا من a وb متساوي لكنهما لا يمثلان نفس الكائن.
وسبب في أن النتيجة منطقية أي أنها True وFalse ..
وذلك لان الروابط تحول العبارة من أي نوع إلى منطقية.
👍🏻
#الاجابة_الصحيحة .....
True
False
لأن محتوى كلا من a وb متساوي لكنهما لا يمثلان نفس الكائن.
وسبب في أن النتيجة منطقية أي أنها True وFalse ..
وذلك لان الروابط تحول العبارة من أي نوع إلى منطقية.
👍🏻
إ₰...👨🏻💻CODE👩🏻💻...₰❥
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace E_Channel
{
public static class Program
{
public static void Main()
{
Console.WriteLine("Welcome...members of the C# channel");
Console.WriteLine("------------------\n");
Console.WriteLine("To join all programming channels of ❥ツ");
Console.WriteLine("\nJoin via the following links :-");
string C_sharp;
string C_plusplus;
string programming;
C_sharp="barmaja_Csharp";
C_plusplus="barrmaja";
programming="language_barmaja";
Console.WriteLine("\n•┈┈┈•❈••✦✾✦••❈•┈┈┈•");
Console.WriteLine("\nC# Language ➺┊ @"+ C_sharp );
Console.WriteLine("\nC++ Language ➺┊ @"+ C_plusplus);
Console.WriteLine("\nProgramming languages library ➺┊ @"+ programming);
Console.WriteLine("\n•┈┈┈•❈••✦✾✦••❈•┈┈┈•");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Welcome...members of the C# channel
------------------
To join all programming channels of ❥ツ
Join via the following links :-
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
C# Language ➺┊ @barmaja_Csharp
C++ Language ➺┊ @barrmaja
Programming languages library ➺┊ @language_barmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace E_Channel
{
public static class Program
{
public static void Main()
{
Console.WriteLine("Welcome...members of the C# channel");
Console.WriteLine("------------------\n");
Console.WriteLine("To join all programming channels of ❥ツ");
Console.WriteLine("\nJoin via the following links :-");
string C_sharp;
string C_plusplus;
string programming;
C_sharp="barmaja_Csharp";
C_plusplus="barrmaja";
programming="language_barmaja";
Console.WriteLine("\n•┈┈┈•❈••✦✾✦••❈•┈┈┈•");
Console.WriteLine("\nC# Language ➺┊ @"+ C_sharp );
Console.WriteLine("\nC++ Language ➺┊ @"+ C_plusplus);
Console.WriteLine("\nProgramming languages library ➺┊ @"+ programming);
Console.WriteLine("\n•┈┈┈•❈••✦✾✦••❈•┈┈┈•");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Welcome...members of the C# channel
------------------
To join all programming channels of ❥ツ
Join via the following links :-
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
C# Language ➺┊ @barmaja_Csharp
C++ Language ➺┊ @barrmaja
Programming languages library ➺┊ @language_barmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...👨🏻💻CODE👩🏻💻...₰❥
#تطبيق_لاستخدام_اداة_الشرط if :-
برنامج لفحص درجة طالب اذا كانت اقل من 60 علامة يعتبر Failed :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public static class Program
{
public static void Main()
{
const int Default = 60;
int Marks;
Console.Title = "IsFailed?";
Console.Write("Enter Student Mark: ");
Marks = Convert.ToInt16(Console.ReadLine());
if (Marks < Default)
Console.Write("Failed");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Student Mark: 30
Failed
#تطبيق_لاستخدام_اداة_الشرط if :-
برنامج لفحص درجة طالب اذا كانت اقل من 60 علامة يعتبر Failed :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public static class Program
{
public static void Main()
{
const int Default = 60;
int Marks;
Console.Title = "IsFailed?";
Console.Write("Enter Student Mark: ");
Marks = Convert.ToInt16(Console.ReadLine());
if (Marks < Default)
Console.Write("Failed");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Student Mark: 30
Failed
إ₰...👨🏻💻CODE👩🏻💻...₰❥
#تطبيق_استخدام_اداة_الشرط_if_للمعادلات_الرياضية:-
× بملأحظة التابع الرياضي التالي :
y = ln(x − 1) ∶ x > 1
يتضح من المعادله ان الشرط ان تكن
( x >1 )
فيجب التحقق من أن دخل التابع اللوغاريتمي هو موجب تماما وذلك بشرط الـif كألتالي :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
double x, y;
Console.WriteLine("Calculating y = ln(x-1)");
Console.WriteLine("Note that x > 1");
Console.Write("Enter x =");
x = Convert.ToDouble(Console.ReadLine ());
if (x > 1)
{
y = Math.Log(x - 1);
Console.Write("y = " + y);
}
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Calculating y = ln(x-1)
Note that x > 1
Enter x =3
y = 0.693147180559945
#تطبيق_استخدام_اداة_الشرط_if_للمعادلات_الرياضية:-
× بملأحظة التابع الرياضي التالي :
y = ln(x − 1) ∶ x > 1
يتضح من المعادله ان الشرط ان تكن
( x >1 )
فيجب التحقق من أن دخل التابع اللوغاريتمي هو موجب تماما وذلك بشرط الـif كألتالي :
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
double x, y;
Console.WriteLine("Calculating y = ln(x-1)");
Console.WriteLine("Note that x > 1");
Console.Write("Enter x =");
x = Convert.ToDouble(Console.ReadLine ());
if (x > 1)
{
y = Math.Log(x - 1);
Console.Write("y = " + y);
}
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Calculating y = ln(x-1)
Note that x > 1
Enter x =3
y = 0.693147180559945
إ₰...👨🏻💻CODE👩🏻💻...₰❥
#تطبيق_لاستخدام_اداة_الشرط if_else :-
* كود لفحص علامة الطالب اذا كانت اكبر من 60 يعتبر passed مالم failed :-
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
const int Default = 60;
int Marks;
Console.Write("Enter Student Mark:");
Marks = Convert.ToInt16(Console.ReadLine());
if (Marks < Default)
Console.Write("Failed");
else
Console.Write("Passed");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Student Mark:80
Passed
#تطبيق_لاستخدام_اداة_الشرط if_else :-
* كود لفحص علامة الطالب اذا كانت اكبر من 60 يعتبر passed مالم failed :-
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
const int Default = 60;
int Marks;
Console.Write("Enter Student Mark:");
Marks = Convert.ToInt16(Console.ReadLine());
if (Marks < Default)
Console.Write("Failed");
else
Console.Write("Passed");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Enter Student Mark:80
Passed
إ₰...👨🏻💻CODE👩🏻💻...₰❥
#تطبيق_استخدام_اداة_الشرط if-else
_للمعادلات_الرياضية
**كود لحل معادلة من الدرجة الثانية
aX^2 + b X + c = 0
كل من a وb وc ثوابت تختلف من معادلة لأخرى.
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
Console.Title = "Equation Solver By Eng27";
Console.WriteLine("Equation : A x^2 + B x + C");
Console.WriteLine("Please Enter A,B And C:");
Console.Write("A = ");
double A = Convert.ToDouble (Console.ReadLine());
Console.Write("B = ");
double B = Convert.ToDouble (Console.ReadLine());
Console.Write("C = ");
double C = Convert.ToDouble (Console.ReadLine());
double delta = B * B - 4 * A * C;
if (delta>0)
{
double x1 = (- B + Math.Sqrt (delta))/(2*A);
double x2 = (- B - Math.Sqrt (delta))/(2*A);
Console.WriteLine("x1 = " + Math.Round (x1,2));
Console.WriteLine("x2 = " + Math.Round(x2, 2));
}
else if (delta == 0)
{
double x = -B / (2 * A);
Console.WriteLine("x1 = x2 = " + Math.Round(x, 2));
}
else
Console.WriteLine("Cannot be Solved!");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Equation : A x^2 + B x + C
Please Enter A,B And C:
A = 8
B = 4
C = 2
Cannot be Solved!
#تطبيق_استخدام_اداة_الشرط if-else
_للمعادلات_الرياضية
**كود لحل معادلة من الدرجة الثانية
aX^2 + b X + c = 0
كل من a وb وc ثوابت تختلف من معادلة لأخرى.
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp
{
public static class Program
{
public static void Main()
{
Console.Title = "Equation Solver By Eng27";
Console.WriteLine("Equation : A x^2 + B x + C");
Console.WriteLine("Please Enter A,B And C:");
Console.Write("A = ");
double A = Convert.ToDouble (Console.ReadLine());
Console.Write("B = ");
double B = Convert.ToDouble (Console.ReadLine());
Console.Write("C = ");
double C = Convert.ToDouble (Console.ReadLine());
double delta = B * B - 4 * A * C;
if (delta>0)
{
double x1 = (- B + Math.Sqrt (delta))/(2*A);
double x2 = (- B - Math.Sqrt (delta))/(2*A);
Console.WriteLine("x1 = " + Math.Round (x1,2));
Console.WriteLine("x2 = " + Math.Round(x2, 2));
}
else if (delta == 0)
{
double x = -B / (2 * A);
Console.WriteLine("x1 = x2 = " + Math.Round(x, 2));
}
else
Console.WriteLine("Cannot be Solved!");
Console.ReadKey();
}
}
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barmaja_Csharp↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
إ₰...Output....₰❥
Equation : A x^2 + B x + C
Please Enter A,B And C:
A = 8
B = 4
C = 2
Cannot be Solved!