Ask your own question, for FREE!
Mathematics 22 Online
OpenStudy (imrankhan):

c program a bycicle has 4bit lock which can be opened only if there are at least 2 ones in the code. write a program to enter decimal code and verify it can open the lock

OpenStudy (primeralph):

Just check each digit? If number of ones >= 2, it opens it. What else?

OpenStudy (imrankhan):

need code

OpenStudy (kc_kennylau):

I don't know C but I know java, so here's basically the pseudocode: make an integer called count whose value is 0; for (n from 1 to 4) if(the nth digit of the string is 1) add one to count; if (count>=2) say yes; Here's the actual java code: int count = 0; for (int n=0; n<4; n++) if(str.charAt(n)==1) count++; if (count>=2) return true; I don't know java but I think that java and c are similar so you can just convert it :)

OpenStudy (primeralph):

Here come the Java people. @kc_kennylau Nice try though.

OpenStudy (kc_kennylau):

xD

OpenStudy (imrankhan):

thnx for help :-)

OpenStudy (kc_kennylau):

no problem :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!