recursion

pls help me.. i need to make a program using recursion.. for example.. user will input 3+2.. the concept of recursion should be 3+1+1 and that the program will output 5.. same as in multiplication..example: input:2*3..concept of recursion:2+2+2 as well as in subtraction:ex:4-2 concept:4-1-1..output=2 and in division..input:4/2 output:2 concept:4-2-2.. pls...


ok.. this is all ive done..(just only for addition)
#include <iostream.h>
#include <conio.h>

int add(int n;int m);
int main()
{
int num1,num2;
add(num1,num2);
return 0;
}
int add(int n;int m)
{
int N
if(m==1)
for(N=1;N<=m;N++)
cout<<N;
else
return n+add(n;m=1)
}
pls help..
Uh, I don't see how that could possibly be recursion. Recursion is the concept of a function calling itself up to a certain point to simplify the execution of an otherwise lengthier code block.
my code looks ugly but i am a newbie too.. hopefully it's useful to you, peace.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

int add(int n,int m);
int mult(int t, int n, int m);

int main(){
    
int num1,num2,temp;

cout << "Please enter first number: " << endl;
cin >> num1;
cout << "Please enter second number: " << endl;
cin >> num2;
temp = num1;
cout << add(num1,num2) << endl;
cout << mult(temp,num1,num2) << endl;
system("pause");
return 0;
}

int add(int n,int m){
    if(m==0)
    return n;
    else
    return add(n+1,m-1);
}

int mult(int t, int n, int m){
    if(m==1)
    return n;
    else
    return mult(t,n+t,m-1);
}
1
2
3
4
int mul(int n, int m) {
    if(m==1) return n;
    return n+mul(n, m-1);
}


you should be able to solve the others out..
Topic archived. No new replies allowed.