# Thread: Division By Subtraction

1. ## Division By Subtraction

In This Code, Shown Below, Find The String W/c Satisfies The Problem...

2. Code:
```#include <iostream.h>
#include <conio.h>
int main()
{
int x;
int y;
int product = 0;

cout<<"input first number:";
cin>>x;
cout<<"input second number:";
cin>>y;

for(int i=0; i<x; i++)
{
product +=y;
}

cout<<"Product is:"<<product;
getch();
return 0;
}```

3. #include <iostream>

remove conio.h
and replace getch by something portable (see FAQ)

So what is the problem? you want to replace addiction with substraction to calculate x/y? Or what?

using subtraction to calculate x/y

5. Originally Posted by blacksnake
using subtraction to calculate x/y
so show the code that USES substruction, and describe your problem with it

the problem looking for is input two numbers and compute for division using subtraction operator...

7. Originally Posted by blacksnake
the problem looking for is input two numbers and compute for division using subtraction operator...
It is not a problem - just assignment description. Show your code you have a problem with

Code:
```#include <iostream.h>
int main()
{
int x;
int y;
int rem;
int quotient = 0;

cout<<"input first number:";
cin>>x;
cout<<"input second number:";
cin>>y;

for(int i=0; i<y; i--)
{
quotient -=x;
}

cout<<"Quotient is:"<<quotient<<"Remainder is:"<<rem;
return 0;
}```
Is there a problem with this code?

9. could you explain your algorithm? in English?

process:

1. Input two numbers
2. compute for division but using subtraction operator...just like multiplication using addition
3. compute for the remainder(rem=x/y)

example for process#2 :

100/10=10
100-10-10-10-10-10-10-10-10-10-10=0

11. @Vart
there is no spoon
A little off topic, but does that mean somthing to do with the ladies? You "grab a spoon" or somthing of that context? Lol., sorry but Im intersted in the quote.

12. Originally Posted by swgh
@Vart

A little off topic, but does that mean somthing to do with the ladies? You "grab a spoon" or somthing of that context? Lol., sorry but Im intersted in the quote.
Matrix
lift (before freeing Morpheus)
Neo looks up:
- There is no spoon, - and shouts the cabin down going with Trinity up.

13. Originally Posted by blacksnake
2. compute for division but using subtraction operator...just like multiplication using addition
100-10-10-10-10-10-10-10-10-10-10=0
So you should
count number of substructions before y goes to 0.
you don't know it in the beginning
Code:
```1. counter = 0
2. if (y > x) {y-=x; counter++}
3. goto 2```
when finished counter contains a result, y - reminder of division

Now write it in more details, and then - write a code that does it

14. I think I took it as the wrong verison of the meaning then. Thanks Vart.

15. Originally Posted by vart
So you should
count number of substructions before y goes to 0.
you don't know it in the beginning
Code:
```1. counter = 0
2. if (y > x) {y-=x; counter++}
3. goto 2```
when finished counter contains a result, y - reminder of division

Now write it in more details, and then - write a code that does it
it is a little bit confused, is it possible to use for loop to satisfy the equation?

Popular pages Recent additions