Question:
How to solve c puzzles?
parag.paul
2008-06-15 21:30:52 UTC
Other than going through , http://concentratedlemonjuice.blogspot.com/2008/06/c-and-c-compilations-questions-puzzles.html
Four answers:
anonymous
2008-06-15 21:47:09 UTC
I looked at one of his "C++ puzzles". It doesn't actually present a puzzle to solve. All I saw there was a fairly pedestrian discussion of operator overloading, with some moderately interesting reasons why the language is designed the way it is. I can only see two ways to answer your question:



1) The "puzzles" on that site are not there for you to solve. They're there for the author of the site to demonstrate his erudition to the world.



2) If there are real puzzles you want to solve, you solve them by understanding the underlying structure of the language to see why things were done as they were.



If you want more information on C, look here:



http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1213591498&sr=8-1



and if you want more information on C++, look here:



http://www.amazon.com/C-Programming-Language-Special-3rd/dp/0201700735/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1213591542&sr=1-1



A warning: neither of those books is especially useful for beginners. If you don't know anything about either, start with something like "A C Primer Plus" or its sister on C++. Both of them, though, are indespensible references once you know a bit about the languages.
The King Of Hell
2008-06-15 21:40:02 UTC
Buy The Book "C Puzzles"
?
2016-10-23 06:33:25 UTC
regrettably James's code is going in opposite of what you want yet this may restoration that difficulty: /*This code retrives the utmost order bit (AND a million) shifts the quantity to the left and retrives the utmost order bit (AND a million) lower back until eventually eventually it truly is grabbed each of the bits in kind int n<<=a million is such as n = n << a million which shifts the bits to the left a million position it truly is such as multiplying by ability of utilising 2 & a million does a binary and with the bit you're comparing... a million & a million = a million, a million & 0 = 0 */ #comprise significant(){ int n,i; int length = sizeof(int)*8; /*be particular kind of bits*/ printf("enter a decimal quantity: "); scanf("%d", &n); //get quantity from man or woman printf("Binary: "); for(i=0;!((n>>length-a million)&a million);i++,n<<=a million); /* get first a million bit*/ for(;i>length-a million)&a million); go back 0; } edit: in case you prefer to stick to Roger's code be particular you upload braces for the if to get rid of a optimal perfect 0 void prtBits(int n){ if(n){ // if isn't 0 prtBits(n>>a million); // call it lower back with the quantity bitshifted to the major suitable (>>) printf("%d", n&a million); / print interior the slightest degree. } }
Kantri
2008-06-15 21:46:45 UTC
it is very very is do more puzzles


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...