/*
QUESTION:
Write a code for division using recursion in this recursive division you can only use subtraction operator i.e '-'
*/
//CODE
#include <iostream>
using namespace std;
int quotient(int a,int b,int q=0){
if (a<b)
return q;
else
q++;
return(a-b,b);
}
int main(){
cout<<"\n\nEnter dividend: ";
int a;
cin>>a;
cout<<"\n\nEnter divisor: ";
int b;
cin>>b;
cout<<"\nAnswer after division is: "<<quotient(a,b)<<endl;
return 0;
}
QUESTION:
Write a code for division using recursion in this recursive division you can only use subtraction operator i.e '-'
*/
//CODE
#include <iostream>
using namespace std;
int quotient(int a,int b,int q=0){
if (a<b)
return q;
else
q++;
return(a-b,b);
}
int main(){
cout<<"\n\nEnter dividend: ";
int a;
cin>>a;
cout<<"\n\nEnter divisor: ";
int b;
cin>>b;
cout<<"\nAnswer after division is: "<<quotient(a,b)<<endl;
return 0;
}
No comments:
Post a Comment