Use of C++ program to subtraction of two numbers using recursion
- Home
- Calculations
- Use of C++ program to subtraction of two numbers using recursion
- On
- By
- 0 Comment
- Categories: Calculations
Use of C++ program to subtraction of two numbers using recursion
Use of C++ program to subtraction of two numbers using recursion
In this tutorial, we will discuss the Use of C++ program to subtraction of two numbers using the recursion
In this topic, we are going to learn how to subtract two numbers using the recusive function in Cpp language
already we are learned the same concept using the operator
if you want to remember click here, Cpp program to subtract two numbers
program to subtraction of two numbers using recursion
The program allows to enter two integer numbers and then it calculates the subtraction of the given numbers using recursive function of C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int sub(int,int); int main() { int num1,num2; cout<<"Enter two numbers: \n"; cin>>num1>>num2;// cout<<"Subtraction of two numbers : "<<sub(num1,num2); getch(); return 0; } int sub(int num1, int num2)//function definition { if(num2==0) return num1; else return sub((num1-1),(num2-1)); }
When the above code is executed, it produces te following result
Enter two numbers 235 125 Subtraction of two numbers : 110
Approach
- Declare three int type variables num1,num2. num1,num2 are used to received input from the user
- Receive input from the user for num1,num2 to perform subtraction
- Define a recursive function to subtract two numbers
- When the function is called, two numbers will be passed as argument subsequently the subtract of two numbers will be found
- display the result on the screen
Suggetsed post
Similar post
Subtract two numbers in Java language
Subtract two numbers in C language
Subtract two numbers in C++ language
Subtract two numbers in Python language
Subtract two numbers in Java language using method
Subtract two numbers in C language using function