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

A man buys 12 lts of liquid which contains 20% of the liquid and the rest is water. He then mixes it with 10 lts of another mixture with 30% of liquid.What is the % of water in the new mixture?

0 Answers   3i Infotech, Amazon, Canara Bank,


Alok and Bhanu play the following min-max game. Given the expression N = X - Y – Z where X, Y and Z are variables representing single digits (0 to 9), Alok would like to maximize N while Bhanu would like to minimize it. Towards this end, Alok chooses a single digit number and Bhanu substitutes this for a variable of her choice (X, Y or Z). Alok then chooses the next value and Bhanu, the variable to substitute the value. Finally Alok proposes the value for the remaining variable. Assuming both play to their optimal strategies, the value of N at the end of the game would be • 4 • -18 • 9 • 2

0 Answers   TCS,


A cylinder is 6 cms in diameter and 6 cms in height. If spheres of the same size are made from the material obtained, what is the diameter of each sphere?

0 Answers   Mu Sigma,


a farmer has a rectangular plot.he wants to do fencing along one of the side wiyh the help of the posts.two posts being on two corners.he brings 5 post less than what he has initially plan because of which the distance between two consecutive post became 8m instead of 6m.what is the length of the side and number of post

1 Answers   TCS,


If any body having sample papers for NIC please mail me at Poojakalra_leo@yahoo.co.in

0 Answers   NIC,






If you go to Eclerx interview, be sure that u wanna be waiting for several hrs, just for filling the application form it will take 15-20 min followed by hr and aptitude test. if u clear hr then aptitude then u will told to go to ghatkopar or tata bye bye ( will receive a call from hr person ) till now not receive any call

3 Answers   eClerx,


Product of Prime no. between 1 to 20?

5 Answers   Accenture, CTS,


If shalu buys 6 more apples, his carton will weigh 14.5 kilograms.if the weight of one apple is 250 grams.how many apples did he initially had in his carton?

0 Answers  


proof of volume of cone=volume of cylinder/3

1 Answers  


In 80 coins one coin is counterfeit what is minimum number of weighings to find out counterfeit coin

0 Answers   TCS,


sir, ihave cleared my ssc so(acctts) written exam i want to some tips for interveiw

0 Answers  


I want to view the solved model papers from SBI bank.plz email to e at pehchaan10@gmail.com at the earliest

0 Answers  


Categories