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# dictionary with multiple values 
Csharp :: exceldatareader example c# 
Csharp :: mvc write to console 
Csharp :: how to write a list to csv c# 
Csharp :: unity how to destroy child 
Csharp :: c# calculate sum of list 
Csharp :: get array from column datatable c# 
Csharp :: c# video to frames 
Csharp :: check property type of collection c# 
Csharp :: c# even or odd 
Csharp :: how to validate if date is a weekday or weekend c# 
Csharp :: while c# 
Csharp :: c# mongodb get all documents 
Csharp :: c# convert enumb to int array 
Csharp :: Show private fields in Unity Inspector 
Csharp :: .net core identity get user id 
Csharp :: C# short getter setter 
Csharp :: Reverse Coding Challenge 1 
Csharp :: string to char array c# 
Csharp :: asp.net core identity get all roles 
Csharp :: how to store some variables on the device in unity 
Csharp :: how to create function in c# 
Csharp :: unity activate gameobject via script 
Csharp :: in c sharp how do you work the wait function 
Csharp :: get device name c# console 
Csharp :: serial number unity pro 
Csharp :: sum the digits in c# 
Csharp :: c# add list to list 
Csharp :: c# substring reverse 
Csharp :: freeze scene unity 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =