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

Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife?

15 Answers   Microsoft,


a man sells an article at a profit of 20%. if he had bought it for 20% less but sells at the same price, find the gain %.

2 Answers   Quatrro, Student,


Dear Sir, Please send me the last 5 years question paper of Clerkship exam to my mail ID. My mail ID is alam_ershad@hotmail.com

0 Answers   State Bank Of India SBI,


Plz help me to get Aptitute test questions for SBI Clerical exams.

0 Answers   State Bank Of India SBI,


5. if atlantic is found in atlantic ocean, india is found in indian ocean then which of the following cases are true

1 Answers   TCS,






suresh went to market with rs. 100. if he buys 3 pens and 6 pencils he uses up all his money.on the other hand if he buys 3 pencils and 6 pens he would fall short by 20% if he wants to buy equal number of pen and pencils then how many pencils can he buy?

1 Answers  


Information about "Jeane D Arc" and picture?

0 Answers  


the number of shells in a judys collection is 80% of the numbers justins collection if justin has 80 more shells than judy how many shells do they have together

3 Answers  


Find sum of 3 + 5/(1+22) + 7/(1 + 22 + 32) + ......

0 Answers   Flipkart, Wipro,


the credit for integrating the Indian princely states goes to

1 Answers  


P is heavier than Q but lighter than R. Q is heavier than T. S is heavier than P but lighter than V. Who among them is the lightest? (a) V (b) S (c) T (d) R (e) None of these

6 Answers  


can anyone tell me how to prepare techinal apptitude question papers of mainframe.like syntel,capejemini pz let me know

1 Answers   TCS,


Categories