GeekInterview.com
Series: Subject: Topic:
Question: 73 of 248

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

Asked by: Interview Candidate | Asked on: Nov 14th, 2007
Showing Answers 1 - 7 of 7 Answers
sarathi trichy

Answered On : Nov 29th, 2007

View all answers by sarathi trichy

#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();}

Yes  2 Users have rated as useful.
  
Login to rate this answer.
purnendu_patra

Answered On : Dec 11th, 2007

View all answers by purnendu_patra

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;}

Yes  1 User has rated as useful.
  
Login to rate this answer.
gayandevi

Answered On : Jul 15th, 2008

View all answers by gayandevi

Can we use logarithm."logarithm of a number-logarithm of 3".Taking antilog gives the result

Yes  1 User has rated as useful.
  
Login to rate this answer.
tejavadali

Answered On : Sep 10th, 2009

View all answers by tejavadali

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

  
Login to rate this answer.
saipk

Answered On : Dec 9th, 2010

View all answers by saipk

quo=-1;rem=0;//n the number enteredfor(i=0;i<=n;i+=3){quo+=1;}rem=n-i+3;printf("%d is the quotient n%d is the remainder",quo,rem);

  
Login to rate this answer.

Int quoitent=-1, rem=0;int number;while(number>=0){    rem=number;    quoitent +=1;   //quoitent= quoitent+1;    number -=3;   //number=number-3;} 

  
Login to rate this answer.
Alok Mishra

Answered On : Aug 4th, 2011

{geshibot language="c"}#include #include void main() { int i,n; float m,j=0; clrscr(); printf("enter the no"); scanf("%d",&n); if(n==1) { m=0.3333; printf("%f",m); } if(n==2) { m=0.6666; printf("%f",m); } if(n >= 3) { 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(); } }{/geshibot}

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.