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

the plane question was asked.it took off from 7 degree 53' 6.1'' and landed at 8 degree 6' 43.5''.it takes 12 hours to travel between these points.then what will be local time at destination ?

0 Answers   Accenture,


A boy travels 285kms in 6hours in 2 stages.. first stage- 40km. second stage-55km.how much distance does he covers?

6 Answers  


Types of attribute and then describe it.

1 Answers  


If DBMDVUUB = CALCUTTA Then BOMBAY = ?

0 Answers   Baan Infotech,


what is effective role a cdpo

0 Answers  






If the data is for 10 bogies and for every 2 bogies added speed decreases by 5% what will be the speed after 5 hrs.

0 Answers   Changepond,


a man buy a liquid by 12 lts and the mixture is of 20% liquid in water then he makes it in 30% mixture then what is the % of liquid with water.

0 Answers   IIT Delhi,


Past question on Chevron's interview tests

1 Answers   Chevron,


The ratio of no. of boys & girls in a school is 3:2 Out of these what % the boys & 25% of girls are scholarship holders. % of students who are not scholarship holders.?

0 Answers   IIT Delhi,


10 years ago, the average age of a family of 4 members was 24 years. Tow children having been born (with age difference of 2 years), the present average age of the family is the same. The present age of the youngest child is:

2 Answers   SSC,


what is meaning of robust (hewiitt)

3 Answers   Hewitt,


An amount of rs120 is divided between 3 people A,B,C. A<20.B>20. What is the share of B?

3 Answers  


Categories