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
All men of this party are republican . mohan is member of this party. mohan is republican is true or false or camn't say?
Ramesh owns 2/3 of the travel business and sells 3/4 of his shares for Rs. 75000. What is the value of his travel business?
A finishes the work in 10 days & B in 8 days individually. If A works for only 6 days then how many days should B work to complete A's work?
Two trains are travelline at equilateral .Train A is travelling in the direction of earths spin.Other train B is travelling in opposite direction of earths spin.Which trains wheels will wear first?and why?
in pure milk if 20% replaced by water and in this again 20% is replaced by water and again 20% is replaced by water then what is the praportion of milk in that mixture
B is 20 miles east of A. D is 30 miles east of C. E is 10 miles north of D. C is 20 miles north of B. How far E is from A?
Current/most recent employer (Please state full names and address including Country and post code) Current Position Held When would you be available to start work? ONLINE INTERVIEW [INSTRUCTIONS: Give brief answers to all the under listed questions] QUESTIONS ANSWER SPACE 1) What are your years of experience? 2) How do you approach a technical problem? Give an example. How long do you think it would be before you will make a significant contribution to the team/company?
From a vessel on the first day, 1/3rd of the liquid evaporates. On the second day 3/4th of the remaining liquid evaporates. what fraction of the volume is present at the end of the II day.
A cube 3"* 3"* 3" is painted green it is cut into 1"* 1"* 1" how many cubes were painted on atleast on one side
The ratio for Boys to Girls is 6:4. 60% of the boys and 40% of girls take lunch in the canteen. What % of class takes lunch in canteen.
the matrix of a(7,9) was given.the address of the first byte of a(1,1)=1258.it takes 4 bytes to store the nuymber. then calculate the address of the last byte of a(5,8)
a circular track has 100yards. The race of Rabbit and TOuttoise. they started at same point. and move in circular path. in opposite direction.first tortoise run for 1/8 th path, then only rabbit starts,rabbit moved slowly till tortoise meet him, Rabbit had covered 1/6 th distance speed( over earlier speed) to win
Seven members sat around a table for three days for a conference. The member's names were Abhishek, Amol, Ankur, Anurag, Bhuwan ,Vasu and Vikram. The meetings were chaired by Vikram. On the first evening members sat around the table alphabetically. On the following two nights, Vikram arranged the seating so that he could have Abhishek as near to him as possible and absent minded Vasu as far away as he could. On no evening did any person have sitting next to him a person who had previously been his neighbor. How did Vikram manage to seat everybody to the best advantage on the second and third evenings?
A person goes 4/5 of his usual speed reaches 10min late to his destination, time taken?
A school has 30% students from Maharashtra .Out of these 20% are Bombey students. Find the total percentage of Bombay?