Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

long number multiplication

// basic idea is how would you multiply two number on paper

// 	6534584351565431546351314865641313541354
// 										X  5
// _________________________________________
// 32672921757827157731756574328206567706770 


    public static List<int> Function(string N, int n)
    {
        var num = N.ToCharArray().ToList()
                   .Select(s => Convert
                   .ToInt32(s.ToString()))
                   .ToList();
        num.Reverse();

        // initially remainder is 0
        var remainder = 0;
        for (int i = 0; i < num.Count; i++)
        {
            var temp = num[i] * n + remainder;
            var inString = temp.ToString();

            if (inString.Length > 1)
            {
                num[i] = Convert.ToInt32(inString[1].ToString());
                remainder = Convert.ToInt32(inString[0].ToString());
            }
            else
            {
                num[i]= Convert.ToInt32(inString[0].ToString());
                remainder = 0;
            }
        }
        if(remainder!=0)
        {
            num.Add(remainder);
        }
        num.Reverse();
        return num;
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# redirecttoaction with area 
Csharp :: remove duplicate characters in a string c# 
Csharp :: else if c# 
Csharp :: unity create 3d object in script 
Csharp :: How to make game object transparent in unity 
Csharp :: c# merge two xml files 
Csharp :: xamarin picker 
Csharp :: mongodb driver c# nuget 
Csharp :: c# get property type of list 
Csharp :: c# get the first 4 characters in the list 
Csharp :: wpf get function name 
Csharp :: c# array max 
Csharp :: unity set sprite image from script 
Csharp :: c# verify in class exist in list 
Csharp :: unity toint 
Csharp :: input unity 
Csharp :: ef core include 
Csharp :: enum c# 
Csharp :: string to chararray c# 
Csharp :: combobox selected name c# 
Csharp :: how to send button name for method in c# 
Csharp :: selenium scroll to element c# 
Csharp :: take space separated input in c# 
Csharp :: disabling a button if textbox is empty c# 
Csharp :: c# combobox lock edit 
Csharp :: razor concatonate inline 
Csharp :: c# get set 
Csharp :: c# math method to reverse negative or positive 
Csharp :: exceeds your upload_max_filesize ini directive (limit is 2048 KiB). 
Csharp :: how to decrease velocity of a Unity rigidbody 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =