There is something wrong with it. I tried your code like this. int i, n = 8, a[9] = {-1,3,5,1,2,9,10,8,6}; //a[0] is never touched in the logic for(i=1; i<=n ;i++ ) //for ease of understanding starting the array with 1. { if(a[ i ] > n ) continue; else a[ a [ i ] ]*=n; } int x[2], m = 0; for ( int i = 1; i <=n ; i++) { if(a[ i ] % n == 0) continue; else { x[m++ ] = i; if(m == 2) break; } }
After first for loop, the array a has -1, 3, 40, 8, 2, 72, 10, 8, 384 And finally, answer array x has 1 and 4, which is not correct. Could you elaborate your logic in pseudocode? Thanks, Channa On Thu, Jul 30, 2009 at 11:06 PM, Devi G <devs...@gmail.com> wrote: > I'm sorry...... misunderstood the problem and tot the missin numbers are to > be less than n. > Yet it can be modified to suit the pbm. > > Suppose the two missin numbers are greater than n, then m==0 when exitin > the loop. > So they will be n+1 and n+2 only. > > in case, one of the missin numbers is greater than n, then m==1, and can be > simply found by subtracting the (array_sum+x[0] ) from (sumof 1 to n+2) > numbers. > > > On Thu, Jul 30, 2009 at 10:55 PM, Devi G <devs...@gmail.com> wrote: > >> for(i=1; i<=n ;i++ ) //for ease of understanding starting the >> array with 1. >> { >> if(a[ i ] > n ) >> continue; >> else >> a[ a [ i ] ]*=n; >> } >> >> int x[2], m = 0; >> >> for ( int i = 1; i <=n ; i++) >> { >> if(a[ i ] % n == 0) >> continue; >> else >> { >> x[m++ ] = i; >> if(m == 2) break; >> } >> } >> >> x[] now contain the two missing numbers in ascending order. >> > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---