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
Just check each digit? If number of ones >= 2, it opens it. What else?
need code
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 :)
Here come the Java people. @kc_kennylau Nice try though.
xD
thnx for help :-)
no problem :)
Join our real-time social learning platform and learn together with your friends!