Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

multiplication using arrays

// 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 :: copy class c# 
Csharp :: convert list of tuples to dictionary c# 
Csharp :: transform.position.x unity 
Csharp :: Change Level in Unity 
Csharp :: ternary operator in c# 
Csharp :: rotation unity script 2d 
Csharp :: hwo to prevent rotation after hitting an object in unity 
Csharp :: c# convert dictionary object to string 
Csharp :: c# remove all punctuation from string 
Csharp :: limiting the amount of decimal places c# 
Csharp :: convert-integer-to-binary-in-c-sharp 
Csharp :: change size of a unity object 
Csharp :: how to get row index of selected row in gridview asp.net webforms 
Csharp :: make variables in c# 
Csharp :: blazor ref to component in if 
Csharp :: check if value in list c# 
Csharp :: how to insert into a list c# 
Csharp :: jenga db connection 
Csharp :: string tochararray c# 
Csharp :: how to find the multiples of 3 c# 
Csharp :: unity get pivot position 
Csharp :: sorting list by date time dec in c# 
Csharp :: Raycasting to find mouseclick on Object in unity 2d games 
Csharp :: c# make file not read only 
Csharp :: c# show list in richtextbox 
Csharp :: Oculus Unity button press 
Csharp :: c# return tuple 
Csharp :: List C# add from List 
Csharp :: fluent api 
Csharp :: How can I display image from database in asp.net mvc. I created image table and image path as varchar 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =