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
Answer Posted / 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 View All Answers
they asked the temperature problem.it was same as previous papers.the ratio was -t*t/6+4t+12.
The cost of an item is Rs 12.60. If the profit is 10% over selling price what is the selling price ?
Jane works at a fashion design company,and is having problems getting dressed for work. She refuses to wear any color combination that does not go well together as many of her clients may look down upon this. She has two pairs of skirts, brown and blue; three blouses, white, sky blue, and gray; four pairs of stockings, red, black, brown, and blue; and two pairs of shoes, black and brown. The blue skirt cannot be worn with red or brown stockings. Gray does not go well with brown. Black does not go well with brown. 1. If Jane wears black shoes she will not wear: a) red stockings. b) a blue skirt. c) a white blouse. d) blue stockings. e) a sky blue blouse. 2. If Jane is color blind and is unable to determine what outfits went well together, how many possible clothing combinations could she have? a)24 b)32 c)36 d)44 e)48 3. If Jane wears a brown skirt and a white blouse, she could: a)not wear blue stockings. b)not wear brown shoes. c)not wear black shoes. d)wear blue stockings. e)wear red stockings. 4.Jane buys a gray scarf. If she wears the new scarf, then she could: a)not wear blue stockings. b)not wear brown stockings. c)not wear black shoes. d)wear a white blouse. e)wear black stockings. 5.Jane will never wear: a)blue and red together. b)white and red together. c)gray and blue together. d)white and black together. e)white and red together.
A and B decide to speak truth or lie on a day. Another person asks A if he is saying truth or lie. B listens to A whatever he answers. Now the person asks B what A had told. B replies as " A has told that he is a liar". What does B say?
I was married 10 years before my wife was sixth member of my family and now I have a baby and today father died and the average age of my family was same as it was 10 years before. Find my father's age when I was married?
Complete the series..2 2 12 12 30 30 ?
Four persons can cross a bridge in 3, 7, 13, 17 minutes. Only two can cross at a time. Find the minimum time taken by the four to cross the bridge.
A man collects cigarette stubs and makes one full cigarette with every 8 stubs.If he gets 64 stubs how many full cigarettes can he smoke.
If wind flows 160 miles in 330 min, for 80 miles how much time required.
i need icet solved papers 2000 to 20010,and also mock papers,mock online
Find the next series of 1,2,2,4,8,?
If INDIA = JOEJB then BSNZ =?
wind flows 160 miles in 330 min, for 80 miles how much time required.
A lorry starts from Bangalore to Mysore at 6.00 A.M,7.00am.8.00 am.....10 pm. Similarly one another starts from Mysore to Bangalore at 6.00 am,7.00 am, 8.00 am.....10.00pm. A lorry takes 9 hours to travel from Bangalore to Mysore and vice versa. A lorry which has started at 6.00 am will cross how many lorries.
Find the next series: AD DP PL LV ?