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

When DB2 is run in IMS environment an application can access data in a) Only DB2 database b) Only IMS database c) Both DB2 & IMS databases d) None of the above

0 Answers  


A person spending out 1/3 for cloths , 1/5 of the remaining for food and 1/4 of the remaining for travelles is left with Rs 100/- . How he had in the beginning ?

0 Answers   Infosys,


The area of the maximum size of the circle described from the 10 square inch square?

0 Answers   Hexaware,


if 30 men completes a job in 15 days working 9 hrs per day..how much hours per day should 40 men work ?? a ) 35 b)7 1/2 c)30 d) none

8 Answers   Accenture,


Gaurav buys milk at Rs. 60 per litre, adds water to it and then sells it at Rs. 75 per litre. What should be the ratio of milk to water to get a profit of 37.5%?

0 Answers   Cap Gemini,


Complete the series: 5, 20, 24, 6, 2, 8, ?

0 Answers   Infosys,


If substitution is as it's burnout. Didn't remember. But this is one.

0 Answers   3D PLM,


You need to purchase a textbook for nursing school. The book cost $80.00, and the sales tax where you are purchasing the book is 8.25%. You have $100. How much change will you receive back?

4 Answers  


What is the probability of getting 3 or 4 in 3 consecutive rolls of a dice ?

0 Answers   Mecon,


one fast typist type some matter in 2hr and another slow typist type the same matter in 3hr. if both do combinely in how much time they will finish.

0 Answers   Accenture,


10 points are chosen on a plane. Every possible pair of points is joined by a line and the midpoint of the line is marked with red colour. What is the minimum possible number points on the plane which have been marked with red colour?

4 Answers   Syntel,


A chain is broken into three pieces of equal lengths containing 3 links each. It is taken to a backsmith to join into a single continuous one . How many links are to to be opened to make it ?

0 Answers   Infosys,


Categories