We were required to write a program to check whether the
given number was of the form 3^n. ( i.e. 3 to the power n).
I knew that it can be done by bit manipulation but couldn't
make out the logic.
i want a solution in C/C++ language
Answer Posted / sreejesh1987
#include<stdio.h>
#include<conio.h>
void main()
{
int count=0,n,d;
clrscr();
printf("\tDigit 3powern\n");
printf("Enter a no:");
scanf("%d",&n);
d=n;
while(d%3==0)
{
d=d/3;
count++;
}
if(d==1)
printf("\nNumber %d is of 3^%d format",n,count);
else
printf("\nNumber %d is not in 3^n format",n);
getch();
}
| Is This Answer Correct ? | 17 Yes | 6 No |
Post New Answer View All Answers
20% of a 6 litre solution and 60% of 4 litre solution are mixed. What percentage of the mixture of solution ?
A ship went on a voyage after 180 miles a plane statrted with 10 times speed that of the ship. Find the distance when they meet from starting point.
Fill the empty slots. Three FOOTBALL teams are there. Given below the list of maches. played won lost draw Goals for Goals against A 2 2 *0 *0 *7 1 B 2 *0 *1 1 2 4 C 2 *0 *1 *1 3 7 the slots with stars are answers.
The lowest temperature in the night in a city A is 1/3 more than 1/2 the highest during the day. Sum of the lowest temperature and the highest temperature is 100 degrees. Then what is the low temp?
For a 13-bit DAC the MSB resistance is 2kohms. What is the LSB resistance ?
in pure milk if 20% replaced by water and in this again 20% is replaced by water and again 20% is replaced by water then what is the proportion of milk in that mixture
Y catches 5 times more fishes than X. If total number of fishes caught by X and Y is 48, then number of fishes caught by X?
Numbers of animals is 11 more than the number of birds. If the number of birds were the number of animals and number of animals were the number of birds( ie., interchanging number s of animals and birds.), the total number of legs get reduced by one fifth(1/5). How many no. of birds and animals were there?
If INDIA = JOEJB then BSNZ =?
There are 5 red shoes, 4 green shoes. If one draw randomly a shoe what is the probability of getting red shoe
WRITE ABOUT A RECENT VISIT TO A RESTAURANT.
In a family Reshma is elder sister of Ragini . Soni is Reshma's daughter and Saloni is Soni's cousin. Rgini's mother is Rajani. Ramani is the sister-inlaw of Reshma. Who is Soni's grandmother?
In a class of 60 students, a student of weight 45 Kg leaves the class. The average weight of the class is then increased by 200 gms. What is the average weight of the remaining 59 students in the class?
Conversation between two mathematicians: first : I have three children. The product of their ages is 36 .. If you sum their ages . it is exactly same as my neighbour's door number on my left. The second mathematician verifies the door number and says that the not sufficient . Then the first says " o.k one more clue is that my youngest is the youngest" Immediately the second mathematician answers . Can you answer the question asked by the first mathematician? What are the children ages?
A certain type of mixture is prepared by mixing brand A at Rs.9 a kg. with brand B at Rs.4 a kg. If the mixture is worth Rs.7 a kg., how many kgs. of brand A are needed to make 40kgs. of the mixture?