當前位置: 首頁>>代碼示例>>C#>>正文


C# Math.DivRem方法代碼示例

本文整理匯總了C#中System.Math.DivRem方法的典型用法代碼示例。如果您正苦於以下問題:C# Math.DivRem方法的具體用法?C# Math.DivRem怎麽用?C# Math.DivRem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Math的用法示例。


在下文中一共展示了Math.DivRem方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      int[] dividends = { Int32.MaxValue, 13952, 0, -14032,
                                     Int32.MinValue };
      // Define one positive and one negative divisor.
      int[] divisors = { 2000, -2000 };
      
      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);
         }
      }                                
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:25,代碼來源:Math.DivRem

輸出:

2,147,483,647 \ 2,000 = 1,073,741, remainder 1,647
13,952 \ 2,000 = 6, remainder 1,952
0 \ 2,000 = 0, remainder 0
-14,032 \ 2,000 = -7, remainder -32
-2,147,483,648 \ 2,000 = -1,073,741, remainder -1,648
2,147,483,647 \ -2,000 = -1,073,741, remainder 1,647
13,952 \ -2,000 = -6, remainder 1,952
0 \ -2,000 = 0, remainder 0
-14,032 \ -2,000 = 7, remainder -32
-2,147,483,648 \ -2,000 = 1,073,741, remainder -1,648

示例2: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      long[] dividends = { Int64.MaxValue, 13952, 0, -14032,
                           Int64.MinValue };
      // Define one positive and one negative divisor.
      long[] divisors = { 2000, -2000 };
      
      foreach (long divisor in divisors)
      {
         foreach (long dividend in dividends)
         {
            long remainder; 
            long quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}", 
                              dividend, divisor, quotient, remainder);
         }
      }                                
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:25,代碼來源:Math.DivRem

輸出:

9,223,372,036,854,775,807 \ 2,000 = 4,611,686,018,427,387, remainder 1,807
13,952 \ 2,000 = 6, remainder 1,952
0 \ 2,000 = 0, remainder 0
-14,032 \ 2,000 = -7, remainder -32
-9,223,372,036,854,775,808 \ 2,000 = -4,611,686,018,427,387, remainder -1,808
9,223,372,036,854,775,807 \ -2,000 = -4,611,686,018,427,387, remainder 1,807
13,952 \ -2,000 = -6, remainder 1,952
0 \ -2,000 = 0, remainder 0
-14,032 \ -2,000 = 7, remainder -32
-9,223,372,036,854,775,808 \ -2,000 = 4,611,686,018,427,387, remainder -1,808


注:本文中的System.Math.DivRem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。