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
how to build a exercise findig min number of e heap with list imlemented?
Is malloc memset faster than calloc?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is oops c?
What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers
how can f be used for both float and double arguments in printf? Are not they different types?
What is the best way to comment out a section of code that contains comments?
Why is c called a structured programming language?
Are the expressions * ptr ++ and ++ * ptr same?
What is pointer to pointer in c with example?
What is the process to generate random numbers in c programming language?
What is a constant and types of constants in c?
Why we use stdio h in c?
Explain high-order and low-order bytes.
What are called c variables?