if you have to find only the repeated element, you can use the below mentioned code.
for (int i = 1; i < N; i++) { array[i] = array[i] ^ array[i-1] ^ i; } printf("Answer : %d\n", array[N-1]); Thinking for the missing no. On Sun, Sep 11, 2011 at 4:06 PM, ravi maggon <maggonr...@gmail.com> wrote: > > 1. Let x be the missing and y be the repeated element > 3. Calculate the sum of all the elements and sum of squares of all the > elements of array. > > S=Sum of all the elements of array > S1= Sum of squares of all the elements of array > > Sum of first n natural numbers=a= ( n * (n+1) )/2 > Sum of squares of first n natural no=b= n * (n+1) * (2n+1) / 6 > > a=S+x-y > b=S1+x^2- y^2 > > (b-S1)/(a-S)=x+y; > > Now we have 2 equations and 2 variables & hence both x and y can be found. > > On Sun, Sep 11, 2011 at 3:58 PM, parag khanna <khanna.para...@gmail.com> > wrote: >> >> Q.) Take an array of 100 elements and fill it with the no 1 to 100 such that >> one no. should skip and one no. should repeated. Find the no. which is >> repeated and which is skipped. >> >> >> >> >> >> >> -- >> Parag Khanna >> B.tech Final Year >> NIT,Kurukshetra >> >> -- >> 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?hl=en. > > > > -- > Regards > Ravi Maggon > B.E. CSE, Final Year > Thapar University > > www.algorithmguru.com > > "Failure is the opportunity to begin again more intelligently" > -- Regards Ravi Maggon B.E. CSE, Final Year Thapar University www.algorithmguru.com "Failure is the opportunity to begin again more intelligently" -- 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?hl=en.