مراجعة حل لعمليات حساب الإخراج كتحد لأنواع الأرقام المحددة

مكتمل

التعليمات البرمجية التالية هي أحد الحلول الممكنة للتحدي من الوحدة السابقة.

int value1 = 11;
decimal value2 = 6.2m;
float value3 = 4.3f;

// The Convert class is best for converting the fractional decimal numbers into whole integer numbers
// Convert.ToInt32() rounds up the way you would expect.
int result1 = Convert.ToInt32(value1 / value2);
Console.WriteLine($"Divide value1 by value2, display the result as an int: {result1}");

decimal result2 = value2 / (decimal)value3;
Console.WriteLine($"Divide value2 by value3, display the result as a decimal: {result2}");

float result3 = value3 / value1;
Console.WriteLine($"Divide value3 by value1, display the result as a float: {result3}");

هذه التعليمة البرمجية هي مجرد "حل واحد ممكن" لأنه من المحتمل أن يكون هناك عدة طرق لحل هذا التحدي. يستخدم الحل الكثير من التحويل (واستدعاء للتحويل)؛ ومع ذلك، فمن الممكن أن يعمل نهج آخر بشكل جيد على قدم المساواة. ما عليك سوى التأكد من تطابق نتيجتك مع الإخراج التالي.

Divide value1 by value2, display the result as an int: 2
Divide value2 by value3, display the result as a decimal: 1.4418604651162790697674418605
Divide value3 by value1, display the result as a float: 0.3909091

إذا كنت ناجحا، تهانينا! تابع إلى التحقق من المعرفة في الوحدة التالية.

مهم

إذا واجهت مشكلة في إكمال هذا التحدي، فربما يجب عليك مراجعة الوحدات السابقة قبل المتابعة.