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

Find the ratio of the areas of the regular hexagons inscribed in and circumscribed around a circle of radius 10cm.

1 Answers   Cap Gemini,


What is the smallest number by which 2880 must be divided in order to make it into a perfect square ?

0 Answers   Mu Sigma,


Joe started from Bombay towards pune and her friend julie in opposite direction.they meet at a point .distance travelled by joe was 1.8 miles more than that of julie.after spending some both started there way.joe reaches in 2 hours while julie in 3.5 hours. Assuming both were travelling with constant speed.Wath is the distance between the two cities.

0 Answers   Infosys,


cpahlet : shoulder :: ring : ?

0 Answers   CTS,


how to find 4 digit no using the digit 2,2,3,3,3,4,4,4,4

7 Answers  


A student gets 70% in one subject, 80% in the other. To get an overall of 75% how much should get in third subject.

0 Answers   Canara Bank, EDS,


i will come thrice in a minute, twice in a hour, once in a day, who am i?

8 Answers   Infosys, Tech Mahindra,


What are applications of half adder circuit?

2 Answers   GGH, TCS, Wipro,


why would you like to service in group d peon in spite of haveing more higher job?

0 Answers  


Some of the friends decided to go on a picnic they decided to go on a bike if the biker decided to take one pillion with him then there is no means of travel for the people as equal to the no of bike + 1. if they decided to go on two trip three bike r left unused in the second trip find the no of person having bike?

2 Answers   CTS,


There is a 50m long army platoon marching ahead. The last person in the platoon wants to give a letter to the first person leading the platoon. So while the platoon is marching he runs ahead, reaches the first person and hands over the letter to him and without stopping he runs and comes back to his original position. In the mean time the whole platoon has moved ahead by 50m. The question is how much distance did the last person cover in that time. Assuming that he ran the whole distance with uniform speed.

4 Answers   Infosys,


One watch is showing 30 past 3 .What is the angle between minutes & hours hand?

0 Answers   Accenture,


Categories