| | |
Simple Recursion (Multiplying by using Addition)
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 370
Reputation:
Solved Threads: 0
Hello all,
My objective is simple. I have to take in 2 positive integers and multiply them by using addition. This is a recursive problem.
Example of Output:
Please enter 2 positive integers to multiply:
4 2
4 * 2 = 8
The problem is whenever the user types in both numbers, the program window just disappears.
To receive my result, I am suppose to use something like:
x + multiply(x,--y);
Please help me with this...Thank you
My objective is simple. I have to take in 2 positive integers and multiply them by using addition. This is a recursive problem.
Example of Output:
Please enter 2 positive integers to multiply:
4 2
4 * 2 = 8
The problem is whenever the user types in both numbers, the program window just disappears.
To receive my result, I am suppose to use something like:
x + multiply(x,--y);
Please help me with this...Thank you
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int multiply(int x, int y); int main() { int x; int y; cout<<"Please enter 2 positive integers to multiply"<<endl; cin>>x; cin>>y; cout<<x<<" * "<<y<<" = "<<multiply(x,--y)<<endl; system ("PAUSE"); return 0; } int multiply(int x, int y) { if (x == 0) { return 0; } if (x == 1) { return x; } if (x > 1) { return (x + multiply(x,--y)); } }
![]() |
Other Threads in the C++ Forum
- Previous Thread: Help (link lists referent)
- Next Thread: Passing Linked Lists - Syntax
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






