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
Find the next number in the series 0,3,8,15,,24,48,63--
Ms. Anurag Awasthi deposits an amount of Rs. 56500 to obtain a simple interest at the rats of 12% p.a. for 3 years. What total amount will Mr. Anurag Awasthi get at the end of 3 year?
the minimum of (2x+1)**2 + (x+2) is at x =
how to create the alarm using sql queries.In the sense i need to make the computer to produce beep sound for each 1 minute.(hint: by chr(7) we can produce the beep sound)
A theif steals half the total no of loaves of bread plus 1/2 loaf from a backery. A second theif steals half the remaing no of loaves plus 1/2 loaf and so on. After the 5th theif has stolen there are no more loaves left in the backery. What was the total no of loaves did the backery have at the biggining.
20% of a 6 litre solution and 60% of 4 litre solution are mixed. What percentage of the mixture of solution ?
One watch is showing 30 past 3 .What is the angle between minutes & hours hand?
maths
A clock with the hours round the face in Roman block numbers, as illustrated in the sketch fell down and the dial broke into four parts....
A printer produced 176,400 pages in a given day. If the printer was in operation for seven hours during the day, how many pages did it print per minute?
A garrison of 3300 men has provisions for 32 days, when given at a rate of 850 grams per head. At the end of 7 days reinforcement arrives and it was found that now the provisions will last 8 days less, when given at the rate of 825 grams per head. How, many more men can it feed?
WHO WAS GIVEN BEST ACTOR AWAR 2010 IN FILM FARE?
A man shows his friend a woman sitting in a park and says that she the daughter of my grandmother's only son. What is the relation between the two
sadrine's avg on four tests is 80 which of the following cannot be the number of tests on which she earned exactly 80 points
In a soap company a soap is manufactured with 11 parts. For making one soap you will get 1 part as scrap. At the end of the day u have 251 such scraps. From that how many soaps can be manufactured?