Write a C# Sharp program to calculate the quotient of two 32-bit signed integers and also returns the remainder in an output parameter

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to calculate the quotient of two 32-bit signed integers and also returns the remainder in an output parameter.

Expected Output:
2,147,483,647 \ 4,000 = 536,870, remainder 3,647
23,547 \ 4,000 = 5, remainder 3,547
0 \ 4,000 = 0, remainder 0
-12,547 \ 4,000 = -3, remainder -547
-2,147,483,648 \ 4,000 = -536,870, remainder -3,648
2,147,483,647 \ -4,000 = -536,870, remainder 3,647
23,547 \ -4,000 = -5, remainder 3,547
0 \ -4,000 = 0, remainder 0
-12,547 \ -4,000 = 3, remainder -547
-2,147,483,648 \ -4,000 = 536,870, remainder -3,648

الأجوبة

using System;
using System.Text;
namespace exercises {
  class Program {
     public static void Main()
   {
      // Define several positive and negative dividends.
      int[] dividends = { Int32.MaxValue, 23547, 0, -12547,
                                     Int32.MinValue };
      // Define one positive and one negative divisor.
      int[] divisors = { 4000, -4000 };
      foreach (int divisor in divisors)
      {
         foreach (int dividend in dividends)
         {
            int remainder;
            int quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}",
                              dividend, divisor, quotient, remainder);
         }
      }
    }
  }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...