Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You won't find complete C code for your problem at SO. Your first approach isn't that bad. You could do the following:</p> <ol> <li>Multiply n1 and n2, conversion is done by mulitplication and addition, i. e. <code>a{1,2,3} -&gt; 1*100 + 2*10 + 3*1</code>, easy to implement</li> <li>Count the digits of your multiplication result (use division inside a loop)</li> <li>While looping through the digits you can store them back into another array</li> </ol> <p>If you can't or if you don't want to deal with dynamic array allocation, then think about how big your array for storage must be beforehand and perform a static allocation.</p> <p><strong>Edit</strong></p> <p>Based on the discussion another approach:</p> <p>Suppose, that <code>r = n1 * n2</code></p> <ol> <li>Create a n*m 2D array, where <ul> <li>n = number of digits in n2</li> <li>m = number of digits in n1 + 1</li> </ul></li> <li>Within a loop multiply each digit of n1 with one of the elements of n2, store the result in the array, store the result per-digit in the 2D-array, don't forget to add the carry to each digit</li> <li>Repeat 2 with all other digits of n2</li> <li>Now the array is filled and you'll have to add each digits like you would do it on paper, store each result within a target array, take care of the carry again</li> </ol> <p>There is one thing left in the algorithm: Determine the size of the target array, based on the informations within the intermediate array, you can think about this by using pencil and paper ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload