GCD using recursion
GCD using recursion
code:
#include<iostream>
using namespace std;
int GCD(int a,int b){
if(b%a==0) return a;
GCD(b%a,a);
}
int main()
{
int a,b;
while(cin>>a>>b){
cout<<"GCD of "<<a<<" "<<b<<" "<<"is "<<GCD(a,b)<<endl;
}return 0;
}
code:
#include<iostream>
using namespace std;
int GCD(int a,int b){
if(b%a==0) return a;
GCD(b%a,a);
}
int main()
{
int a,b;
while(cin>>a>>b){
cout<<"GCD of "<<a<<" "<<b<<" "<<"is "<<GCD(a,b)<<endl;
}return 0;
}
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন