Note that there are some explanatory texts on larger screens.

plurals
  1. POAdditive Sequence Algorithm
    text
    copied!<p>I am practicing algorithms for interviews and came across this question on <a href="http://www.careercup.com/question?id=14473984" rel="nofollow noreferrer">Career Cup</a> and <a href="https://stackoverflow.com/questions/7911875/additive-sequence">SO</a> An additive sequence number is which when splitted in two different number forms additive seq. </p> <p><code>Ex: 1235 (split it 1,2,3,5)</code> <code>Ex: 12122436(split 12,12,24,36)</code> given a range find all additive seq numbers ?</p> <p>Below is what I tried, I know it is not efficient and not sure about its complexity. Also, It does not find numbers like 53811 and 12122436 which I am interested in finding. I will be really thankful if someone can guide me in right directions or come up with something more simple and efficient. Thanks!</p> <pre><code>#include &lt;stdio.h&gt; void check_two_num_sum(int,int); void check_sum(int); int flag = 0; int main(){ int high,low; printf("Enter higher range\n"); scanf("%d",&amp;high); printf("Enter lower range\n"); scanf("%d",&amp;low); check_two_num_sum(high,low); return 0; } void check_two_num_sum(int high, int low) { flag=0; for(low;low&lt;high;low++) { check_sum(low); if(flag==1) { printf("this value has additive sequence %d \n",low); flag = 0; } } } void check_sum(int input) { int count = 1; int capture, result, temp_res=0, n=0; if(n==0){ result = input%10; n++; input = input/10; capture = input; } while(input!=0) { temp_res = temp_res + input%10; if(count ==2) { if(result == temp_res) { if(capture &lt; 100) { flag = 1; break; } else{ check_sum(capture); } } else { break; } } count++; input = input/10; } } </code></pre>
 

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