This can be done simply by checking and unchecking flag , below code will work :-
void checkPattern(int n) { int cnt=0,flag=1; if(n&1) { while(n) { if(n&1 && flag==1) { cnt++; flag=0; } else if(!(n&1) && flag==0) { cnt++; flag=1; } if(cnt > 3) { break; } n=n>>1; } } if(cnt==3) printf("\npattern found\n"); else printf("\nPattern not found\n"); } On Wed, Apr 4, 2012 at 5:30 AM, Ashish Goel <ashg...@gmail.com> wrote: > verify that the bits of a number are in format 1s followed by 0s followed > by 1s like 1110001 is valid but 100100100 is not > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > -- > 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. > -- 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.