Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Current Affairs » Ancient Egyptian/Russian peasants multiplication in C#

Ancient Egyptian/Russian peasants multiplication in C#

In this article we will see about two operations of multiplication, Ancient Egyptian multiplication and Russian peasants multiplication.

Page Views : 1306
Downloads : 7
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Multiplication.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

When you use your computer or your calculator to make difficult calculations, or when you see your child being easily the following multiplication:

     68
x   43
-----------
  204
272
-----------
2924

We have to remember the suffering of the ancients throughout history to calculate the operations of arithmetic, however left us great works certifying that they were geniuses.

History tells us about two operations of multiplication, Ancient Egyptian multiplication and Russian peasants multiplication.

Ancient Egyptian multiplication

Here is how 43 is multiplied by 68
  1. Start with number 1 in the first column and keep doubling (the first column has powers of two), the largest power of two less than or equal to the the first number(43).
  2. Start with the second number (68) in the second column, keep doubling the number in the second column.
  3. Subtract the largest power of two less than or equal to the first number(43),

    43 - 32 = 11, 

    subtract the largest power of two less than or equal to the remainder(9),

    11 - 8 = 3

    repeat,

    3 - 2 = 1

    repeat until nothing remained,

    1 - 1 = 0

    now you see that 43 = 32 + 8 + 2 + 1. 

  4. To get result, Check the numbers in the second column corresponding to 32, 8, 2, 1 and add them. 
Russian peasants multiplication

See how 43 is multiplied by 68
  1. Write each number at the head of a column. 
  2. Divide the number in the first column by 2, flooring the quotient (drop the remainder), until there is nothing left to divide. 
  3. Keep doubling the number in the second column, until you have doubled it as many times as you divided the number in the first column.
  4. To get result, add up all the numbers in the second column that are next to an odd number in the first column. 
Test operations of multiplication

To test the previous operations of multiplication begin a new project with one form, put the following controls on the form:
  • two controls of TextBox: txtFirst and txtSecond to enter two numbers.
  • two controls of CheckedListBox for Ancient Egyptian multiplication: lstEgyptian1 and lstEgyptian2.
  • two controls of CheckedListBox for Russian peasants multiplication: lstRussian1 and lstRussian2.
  • two controls of Label to print the result: EgyptianResult and RussianResult.
  • three controls of Buttons: btnEgyptianCalc, btnRussianCalc to get the result and btnExit to exit the program.
About the Code

Fill first list:

private void FillListEgyptian1()
{
    int newVlue = 1;
    numFirst = Convert.ToInt32(txtFirst.Text);
    lstEgyptian1.Items.Clear();
    //add powers of two (less than numFirst) to 'lstEgyptian1'
    while (newVlue <= numFirst)
    {
        lstEgyptian1.Items.Add(newVlue);
        newVlue = 2 * newVlue; //the first column has powers of two
    }
}

Fill second list:

private void FillListEgyptian2()
{
    numSecond = Convert.ToInt32(txtSecond.Text);       
    lstEgyptian2.Items.Clear();
    lstEgyptian2.Items.Add(numSecond);
    for(int i = 1; i < lstEgyptian1.Items.Count; i++)
    {
        numSecond = numSecond * 2; //Keep doubling the second number
        lstEgyptian2.Items.Add(numSecond);
    }
}

Check numbers at first column:

private void CheckEgyptianNumbers()
{
    int newNumber = numFirst;
    int i = lstEgyptian1.Items.Count;
    do
    {
        i--;
        int binNumber = (int)(lstEgyptian1.Items[i]);
        if(binNumber <= newNumber) //is power of 2 < newNumber?
        {
            newNumber = newNumber - binNumber;
            lstEgyptian1.SetItemChecked(i, true); //check it
            lstEgyptian2.SetItemChecked(i, true);
        }
    }
    while (i > 0);
}

Add numbers to get the result:

private void GetEgyptianMultiplication()
{
    long TheResult = 0;
    for(int i = 0; i < lstEgyptian2.Items.Count; i++)
    {
        if(lstEgyptian2.GetItemChecked(i) == true)
        {
            TheResult = TheResult + (int)(lstEgyptian2.Items[i]);
            EgyptianResult.Text = TheResult.ToString();
        }
    }
}

You can read the code of Russian peasants multiplication.

We must not forget what previous generations have given us the knowledge, said Isaac Newton "I stand on the shoulders of my predecessors".

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mostafa Kaisoun
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.