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



We were required to write a program to check whether the given number was of the form 3^n. ( i.e. 3..

Answer / 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

More General Aptitude Interview Questions

There are 1000 doors that are of the open-close type. When a person opens the door he closes it and then opens the other. When the first person goes he opens-closes the doors ion the multiples of 1 i.e., he opens and closes all the doors. When the second goes he opens and closes the doors 2, 4 6 8 rely. Similarly when the third one goes he does this for 3 6 9 12 15th doors rely. Find number of doors that are open at last.

0 Answers   Accenture,


Perimeter of the back wheel = 9 feet, front wheel = 7 feet on a certain distance, the front wheel gets 10 revolutions more than the back wheel .What is the distance?

8 Answers   3i Infotech, C DAC, Canara Bank, CMC, GE, Geodesic, Infosys, TCS,


Why 3 comes after 2 And 2 comes after 1 ?

8 Answers  


If on an item a shop gives 25% discount, they earn 25% profit. If they now give 10% discount then what is the profit percentage

27 Answers   Deloitte,


If you take a marker & start from a corner on a cube, what is the maximum number of edges you can trace across if you never trace across the same edge twice, never remove the marker from the cube, & never trace anywhere on the cube, except for the corners & edges?

2 Answers  






Find the next number in the series 1,2,5,10,,15,22--

0 Answers   DSQ Software,


please send 10 year question papers of clerical and probationary officer question papers of sbi bank ........syed0460@gmail.com this is my email id....

0 Answers  


There are 12 boys and 15 girls, How many different dancing groups can be formed with 2 boys and 3 girls. Which of the following fractions is less than 1/3?

0 Answers   Mu Sigma,


Every station in N rail road issue every other station's ticket. some stations are added.Now they have to issue 46 more tickets. say the No.of stations after and before added.

0 Answers   Infosys,


hello i have cleared the exam for clerical post in SBI n now i wish to know bout the type of questions asked in the interview... i m very tensed.. pls let me know if anyone has any idea about it..

0 Answers  


Next number in the series: 77,49,36,18,?

0 Answers   Accenture,


If DDMUQZM is coded as CENTRAL then RBDJK can be coded as ---------

1 Answers   TCS,


Categories