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

Showing Answers 1 - 21 of 21 Answers

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

}


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;

}

saipk

  • Dec 9th, 2010
 

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

  Was this answer useful?  Yes

Alok Mishra

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

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions