GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures
Go To First  |  Previous Question  |  Next Question 
 Data Structures  |  Question 181 of 202    Print  
Without using /,% and * operators. write a function to divide a number by 3.

  
Total Answers and Comments: 4 Last Update: September 11, 2009     Asked by: Rashi Rathi 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: gayandevi
 
Can we use logarithm."logarithm of a number-logarithm of 3".Taking antilog gives the result

Above answer was rated as good by the following members:
raja vignesh, rajani_vaddepalli15, aman15490
November 29, 2007 13:35:48   #1  
sarathi trichy Member Since: October 2007   Contribution: 106    

RE: Without using /,% and * operators. write a function to divide a number by 3.

#include<stdio.h>
#include<conio.h>
void main()
{
int i n;
float j 0;
clrscr();
printf("enter the no");
scanf(" d" &n);
for(i n;i>2;i i-3)
{
j j+1;
if(i 4)
{
j j+1.333333;
}
if(i 5)
{
j j+1.666666;
}
}
printf(" f" j);

getch();

}



 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
December 11, 2007 05:32:04   #2  
purnendu_patra Member Since: December 2007   Contribution: 2    

RE: Without using /,% and * operators. write a function to divide a number by 3.

The number is N the decimal places to which the division will be done is D.

int quot 0 remainder 0 rem 0;

int x 0;


Void DivisionBySubtraction(N D)
{
while(N> 3)

{

N- 3;

++quot;

}

if (N 0)

cout<<"quotient "<<quot;

else

{

while(x<D)

{

N* 10;

while(N> 3)

{ N- 3;

rem++;

}

remainder remainder*10+rem;

if (N 0)
break;
++x;
}
}

cout<<"remainder "<<remainder;

}


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 15, 2008 12:58:34   #3  
gayandevi Member Since: March 2008   Contribution: 2    

RE: Without using /,% and * operators. write a function to divide a number by 3.
Can we use logarithm. logarithm of a number-logarithm of 3 .Taking antilog gives the result
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 10, 2009 21:41:25   #4  
tejavadali Member Since: September 2009   Contribution: 1    

RE: Without using /,% and * operators. write a function to divide a number by 3.

void dvdby3(int n)
{
int count 0 rem;
while(n>0)
{
rem n;//reminder
n n-3;
count++;
}
}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape