Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Which of the following appointments is not made by the President of India? a) Speaker of the LOk Sabha. b) Chief of Air Staff c) Chief of Army

3 Answers   Sodexo,


In 29 words or fewer, describe what you would strive to accomplish if you worked at Google Labs.

3 Answers   Google, Patni, Wipro,


A is twice efficient than B. A and B can both work together to complete a work in 7 days. Then find in how many days A alone can complete the work?

0 Answers   Accenture, BSNL,


Bird is flying 120km/hr b/w b to r. Two trains at b to r at 60 kmph the distance traveled by the bird before it is killed.

0 Answers   Infosys,


There are 3 persons X, Y and Z. On some day, X lent tractors to Y and Z as many as they had. After a month Y gave as many tractors to X and Z as many as they have. After a month Z did the same thing. At the end of this transaction each one of them had 24. Find the tractors each originally had?

6 Answers  


One clock ringes 7 O'clock in 7 sec.In how many seconds it will ring 10 O'clock.

0 Answers   Accenture,


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  


A certain street has 1000 buildings. A sign-maker is contracted to number the houses from 1 to 1000. How many zeroes will he need?

6 Answers   Accenture,


Asish was given Rs. 158 in denominations of Rs 1 each. He distributes these in diff bags, such that ne sum of money of denomination betn 1 and 158 can be given in bags. The min no. of such bags reqd :

2 Answers   Cap Gemini,


three friends a,b,c run around a circular track of length 120m at a speed of 5,7,15m/sec respectively starting simultaneously from the same point in the same direction .how often they three will meet????

5 Answers  


distance D=rt where r & t are +ve and r is constant,as t increses then D_________

10 Answers   Wipro,


In base 10 representation for a rupee 100 paise,then base 8 representation what is rupee value?

0 Answers   Wipro,


Categories