write a c/c++ program that takes a 5 digit number and
calculates 2 power that number and prints it?

Answer Posted / m.choudhury

The problem is 2^(axxxx) where x belongs to {0,1,.....9} & a
belongs to {1,2,3,.....9}. This is clearly not equivalent to
2*(axxxx).

The solution will be easier if we can give the answer in
HEXADECIMAL format.

2^2=(4)DEC=(100)BINARY=(4)HEX
2^4=(16)DEC=(10000)BINARY=(10)HEX
2^7=(128)DEC=(10000000)BINARY=(80)HEX
.
.
.
2^n=(X)DEC=(100.....0)BINARY{n no. of zero after 1}=(Z)HEX
(X is the decimal of 2^n, Z is HEXADECIMAL of 2^n)

To get Z get HEX of (1a) where a = n%4 is the number of
zeros after 1.

Then path n/4 no. of zeros with that.

can anyone suggest the code for integer representation of
2^n , (where n is any integer), with polynomial time
complexity ?

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data structure in c language?

599


hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

1895


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

630


Is null a keyword in c?

730


What is putchar() function?

633






What is maximum size of array in c?

581


What is int main () in c?

621


What is a memory leak? How to avoid it?

569


Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.

655


Does c have function or method?

585


Why does notstrcat(string, "!");Work?

639


What is null pointer constant?

592


What was noalias and what ever happened to it?

590


How can I access an I o board directly?

620


Why we not create function inside function.

1744