Division By Subtraction

This is a discussion on Division By Subtraction within the C++ Programming forums, part of the General Programming Boards category; In This Code, Shown Below, Find The String W/c Satisfies The Problem......

  1. #1
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50

    Exclamation Division By Subtraction

    In This Code, Shown Below, Find The String W/c Satisfies The Problem...
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  2. #2
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50
    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;
    }
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    #include <iostream>

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

    your program calculates x*y using addiction.

    So what is the problem? you want to replace addiction with substraction to calculate x/y? Or what?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50

    reply

    using subtraction to calculate x/y
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by blacksnake
    using subtraction to calculate x/y
    so show the code that USES substruction, and describe your problem with it
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50

    reply

    the problem looking for is input two numbers and compute for division using subtraction operator...
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote 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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50

    reply:

    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?
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    could you explain your algorithm? in English?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50

    reply:

    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
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

  11. #11
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    @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.
    I'm just trying to be a better person - My Name Is Earl

  12. #12
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote 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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote 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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #14
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    I think I took it as the wrong verison of the meaning then. Thanks Vart.
    I'm just trying to be a better person - My Name Is Earl

  15. #15
    Notorious Turbo C killer blacksnake's Avatar
    Join Date
    Jan 2007
    Location
    philippines
    Posts
    50
    Quote 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?
    Turbo C Makes me Sick....i just want to learn data structures in latest c++

    Le Tormente (fr. the torment)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Division using repeated subtraction
    By dbzx in forum C Programming
    Replies: 10
    Last Post: 05-27-2009, 06:07 PM
  2. Get jiffies?
    By pgzh in forum Linux Programming
    Replies: 6
    Last Post: 03-17-2008, 10:30 AM
  3. Binary division of large numbers
    By hooper in forum C Programming
    Replies: 5
    Last Post: 06-01-2007, 02:33 AM
  4. pseudo code for division
    By svaidya in forum C Programming
    Replies: 14
    Last Post: 05-31-2007, 01:48 PM
  5. Modular Division problem
    By Malek in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2003, 06:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21