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
Why isn't any of this standardized in c? Any real program has to do some of these things.
Explain data types & how many data types supported by c?
What are the usage of pointer in c?
What library is sizeof in c?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.
what is the difference between class and unio?
what do you mean by inline function in C?
What is the difference between call by value and call by reference in c?
write a program to find the given number is prime or not
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
How can you convert integers to binary or hexadecimal?
When should the const modifier be used?
Where we use clrscr in c?
How #define works?