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

a person who decided to go weekend trip should not exceed 8 hours driving in a day average speed of forward journey is 40 mph.due to traffic in sun days the return journey average speed is 30 mph.how far he can select a picnic spot.

0 Answers   TCS,


1,2,3,4,5,6,7,8,9 station. route between any 2 station is there only if the 2 digit nob. is divisible by 3. e.g. route exist between 1 to 2 because 12 is divisible by 3 how many station have routes to 8 either direct or indirect

0 Answers   Infosys,


how can i get answers of all question.

0 Answers   State Bank Of India SBI,


How much area in sqmt of 14 fit dia cirlce???

6 Answers   IBM,


Ramesh working alone on a job takes 12 days more than what he would have taken if Suresh had worked along with him while Suresh working alone on the same job takes 27 days more than what he would have taken if Ramesh had worked along with him. Find the time that both of them would take together to do the job.

0 Answers   Cap Gemini,


If 5+3+2=151012, 5+4+5=202504, 7+2+5=143542 then 8+6+2= ?

21 Answers   DRDO, Facebook, Infosys, intract-crm, Mavensoft, Wipro,


how many numbers upto 2oo which are divisible by 2 11 ?

1 Answers   Wipro,


Four Members A, B, C, D are playing a game .A person losing a game should double the amount of others .B, C, D are losing in order after three games .The amount after 3 games are A&B having 40,D is having 16&C 80.What amount did B have?

0 Answers   Accenture,


If two cards are taken one after another without replacing from a pack of 52 cards what is the probability for the two cards be queen.

6 Answers   BFL, Cadence,


1. 10 men and 10 women are there, they dance with each other, is there possibility that 2 men are dancing with same women and vice versa? a) 22 b) 20 c) 10 d) none

2 Answers   TCS,


3 red and 4 blue balls are in a basket. A member of PPTeam is drawing balls from the basket.What is the probablity of getting the 3 red balls simultaneously?

0 Answers   Hexaware,


find missing no 5 12 23 30 17 8 ? 3

11 Answers   HCL,


Categories