Thread: Multiplication table using only recursion

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    Multiplication table using only recursion

    I'v been asked to write the function that print the multiplication table until x*y using only recursion.
    the function call will be mult(x,1,y);
    void mult(int x, int base, int y).
    Have any idea how to slove it?

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The rule is as simple as this : You post your try and then you get feedback
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    My idea was : to print (x/x)*base each row
    And then to promote base.

    printf("%2d ",base);
    if(base==y) return;
    mult_table(x,++base,y);

    my problem is when i stop recursion it back with base =5 and i didnt found how to use it.
    Last edited by Oleg Suharevich; 01-12-2013 at 10:35 AM.

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Post your code in code tags next time, like this
    [code]/*your program*/[/code]

    I do not understand your problem :/
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    Ill.
    My problem is to print each row after the first one .
    I print the first row 1-10
    but when the recursion is start to return it back with base 10 (in case 10*10) and i cant use that base to print the next row.
    Have no idea how I need to make it.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Any problem which can be solved iteratively can also be solved using recursion. Why not make the iterative version first and then try to convert it to a recursive version?

    for x = 1 to 10
    for y = 1 to 10
    ...
    end for
    end for

  7. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    4
    I know , thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiplication table
    By yatesj05 in forum C Programming
    Replies: 7
    Last Post: 04-17-2011, 02:46 AM
  2. C Multiplication Table
    By trueman1991 in forum C Programming
    Replies: 2
    Last Post: 11-11-2009, 07:58 AM
  3. Multiplication table
    By freddyvorhees in forum C++ Programming
    Replies: 6
    Last Post: 08-02-2008, 11:09 AM
  4. multiplication table
    By SpEkTrE in forum C Programming
    Replies: 2
    Last Post: 12-09-2003, 04:46 PM
  5. multiplication table help
    By cprogstudent in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:32 PM