| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|||||||
| ds. c , c++ Interview / Technical Questions Kindly solve an many as questions you can. It will sharpen your skills and those solutions will help others too. |
![]() |
|
|
LinkBack | Thread Tools | Rate Thread | Display Modes |
|
|
#1 (permalink) |
|
Moderator
Join Date: Nov 2006
Age: 25
Posts: 227
Thanks: 1 Thanked 12 Times in 9 Posts Thanks: 1
Thanked 12 Times in 9 Posts
Rep Power: 6
|
C language - How to write a C program to find the power of 2 in a normal way and in single step?
How to write a C program to find the power of 2 in a normal way and in single step?
|
|
|
|
|
|
#2 (permalink) | |
|
Junior Member
Join Date: Feb 2008
Posts: 1
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?
Quote:
printf("The number is a power of two"); Eg: Consider 8 8---> 1000 7---> 0111 8&7-->0000 Therefore 8 is a power of 2!! Consider 12 12---> 1100 11---> 1011 12&11-->1000 Therefore 12 is not a power of two |
|
|
|
|
|
|
#3 (permalink) |
|
Junior Member
Join Date: Apr 2007
Posts: 6
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?
#include<math.h>
pow(2,i); // 2 raise to i......i can have any value |
|
|
|
|
|
#4 (permalink) |
|
Super Moderator
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117 Thanked 241 Times in 198 Posts Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51
|
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?
1<<n;
/* above statement is equal to 2 power n; you can change value of n to any value. But keep in mind that this statement abilities are restricted by the size of integer. So you can't try with too big value for n */ Thanks, Krishna
__________________
Give 1 cup rice to a hungry Indian just by a mouse click. No money, no form filling, no hassle... Click here for the donation. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|