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
One ship goes along the stream direction 28 km and in opposite direction 13 km in 5 hrs for each direction.What is the velocity of stream? `
In a company 30% are supervisors and 40% employees are male if 60% of supervisors are male. What is the probability that a randomly chosen employee is a male or female?
In a cycle race there are 5 persons named as J, K, L, M, N participated for 5 positions so that in how many number of ways can M make always before N?
There six red shoes & 4 green shoes .If two of the shoes are drawn.What is the probability of getting two red shoes.
a solution is prepared by mixing two solution with sprit 20% & 60%…In what ration they should be mixed to get the 50% sprit in resultant solution .
How will u divide two numbers in a MACRO?
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.
Olympic race : 4 contestants : Alan,charlie, Darren ,Brain. There are two races and average is taken to decide the winner.one person comes at the same position in both the race. Charlie always come before darren. Brian comes first once. Alan comes third at least once. Find the positions. Alan never comes last. Charlie & darren comes 2nd at least once.
A clock is late by 1 minute 27 seconds in a month. Then how much will it be late in 1 day?
The age of the grand father is the sum of his three grandsons.The second is 2 year younger than first one and the third one is 2 year younger than the second one. Then what will be the age of the grandfather?
Calculate the area of the triangle in square cm if a right angled triangle where the length of the shorter leg is one third of the length of its hypotenuse. And the length of the shorter leg is 7 cm.
What is the smallest number by which 4880 must be divided in order to make it into a perfect square ?
(x-y/3)-(y-x/3)=?
In a queue, a man is standing at the position 10th from the front and 15th from behind. How many persons are standing in the queue?
+ means * and * means / and / means % what is the value of these question 2+3*5/7 it was two question of these type.