Thread: Division By Subtraction

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    #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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by blacksnake
    using subtraction to calculate x/y
    so show the code that USES substruction, and describe your problem with it
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    could you explain your algorithm? in English?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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,688
    @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.
    Double Helix STL

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  14. #14
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    I think I took it as the wrong verison of the meaning then. Thanks Vart.
    Double Helix STL

  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)

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