Understanding Complex Integer Operations

hw 5 hints n.w
1 / 12
Embed
Share

Explore different methods to solve complex integer operations efficiently, including managing complexity, debugging, converting integers to strings, performing addition, and comparison of numbers. Learn valuable tips and tricks to handle integer calculations effectively.

  • Integer Operations
  • Complexity Management
  • Debugging Tips
  • Number Comparison
  • String Conversion

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Hw 5 Hints

  2. Managing Complexity Many different ways to solve this problem Write and test one function at a time Try to use a statically allocated array with say, 100 char Convert to a dynamically allocated array later Creating little helper functions Reverse string Multiply up to 10 Max, min

  3. Debugging Remember to check operands of different lengths Use a global debugging counter to track memory allocation Update the counter whenever new and delete are called

  4. The Least Significant Digit First Integer to string Addition

  5. Integer to String 123 -> 123 123 % 10 = 3, 3 = 3 + 0 123 / 10 = 12 12 % 10 = 2, 2 = 2 + 0 12 / 10 = 1 1 % 10 = 1, 1 = 1 + 0 1 / 10 = 0 // terminate

  6. Addition 999 999 + 99 + 99 ------------ ------------ 8 098 999 999 + 99 + 99 ------------ ------------ 98 1098

  7. The Most Significant Digit First Multiplication Comparison of two numbers of the same length

  8. Multiplication 1111 X 111 ------------ 1111 1111 + 1111 ------------- 12321

  9. Same as 1111 1111 X 111 X 111 ------------ ------------ 1111 1111 1111 1111 + 1111 + 1111 ------------- ------------- 12321 12321

  10. Same as 1111 x 111 = ((1 x 1111) x 10 + 1 x 1111) x 10 + 1 x 1111

  11. Comparison If two numbers have the same length The most significant digit decides which number is bigger If they are the same, compare the next digit

  12. Some Possible Ways to Store 123 123 Easier to print and extract input Easier to write the string conversion constructor Easier to multiply Easier to compare numbers 321 Easier to write the integer conversion constructor Easier to add two numbers Lowest significant digit first

More Related Content