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 the easiest sorting method to use?

637


What is structure packing in c?

612


Is it better to bitshift a value than to multiply by 2?

662


How do you view the path?

672


How reliable are floating-point comparisons?

632






Write a program to reverse a given number in c?

603


What is volatile keyword in c?

587


How do you sort filenames in a directory?

716


If I have a char * variable pointing to the name of a function ..

657


What is the heap in c?

647


Difference between exit() and _exit() function?

659


Is that possible to add pointers to each other?

907


write a program to find the given number is prime or not

3847


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

643


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

722