- menghitung gcd dari dua bilangan bulat positif
- cpp
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int gcd(int c,int d){
if(d==0) return(c);
if(c<d) return(gcd(d,c));
return(gcd(c-d,d));
}
int main(int argc, char** argv) {
int a,b;
cin>>a;cin>>b;
cout<<gcd(a,b);
return 0;
}
Tidak ada komentar:
Posting Komentar