Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

multiplication of long number

// 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 :: .net core web app get dll name 
Csharp :: c# binding add combobox with enum values 
Csharp :: what are access modifiers in c# 
Csharp :: c# copy files from one folder to another 
Csharp :: c# run batch file 
Csharp :: how to check if List<T element contains an item with a Particular Property Value in c# 
Csharp :: sort file name with C# 
Csharp :: how to set foreground from code wpf 
Csharp :: c# kill one excel process 
Csharp :: c# signalr console app client example 
Csharp :: c# get function name 
Csharp :: how to check if the value is alphabet and numbers only only in c# 
Csharp :: test how catch exception c# 
Csharp :: get unique array based on value in c# 
Csharp :: c# #region #endregion 
Csharp :: c# list.foreach 
Csharp :: how to add to a list only items that are not already in the list c# 
Csharp :: how to make pc bsod C# 
Csharp :: char array 
Csharp :: change sprite color unity 
Csharp :: get the number of cpu c# 
Csharp :: c# replace multiple characters 
Csharp :: string substring c# before 
Csharp :: c# parse number from string 
Csharp :: ActionExecutingContext result response return 
Csharp :: what is list in c# 
Csharp :: sum of digit of number c# 
Csharp :: get min date in list c# 
Csharp :: audiosource unity 
Csharp :: .net 4.5 use tls 1.2 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =