Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is c procedural or object oriented?

953


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

1003


What is queue in c?

1033


What does struct node * mean?

965


how to write optimum code to divide a 50 digit number with a 25 digit number??

3204


How will you find a duplicate number in a array without negating the nos ?

2082


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

1038


Tell us two differences between new () and malloc ()?

1115


What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?

1271


Can you please compare array with pointer?

1031


What is volatile keyword in c?

997


What is null pointer in c?

948


What are register variables? What are the advantage of using register variables?

1128


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

16590


What is a union?

989