GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures
Go To First  |  Previous Question  |  Next Question 
 Data Structures  |  Question 181 of 198    Print  
Without using /,% and * operators. write a function to divide a number by 3.

  
Total Answers and Comments: 3 Last Update: July 16, 2008     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: 1    

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    


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape