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 / 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 |
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
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 ?
The area of the maximum size of the circle described from the 10 square inch square?
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
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%?
Complete the series: 5, 20, 24, 6, 2, 8, ?
If substitution is as it's burnout. Didn't remember. But this is one.
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?
What is the probability of getting 3 or 4 in 3 consecutive rolls of a dice ?
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.
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?
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 ?