Learn Computer Science programming - C# and C++ Algorithms

 
GCD
The greatest common divisor (GCD) of two or more integers is the largest positive integer that divides the numbers without a remainder.
Code
gcd.zip
File Size: 4385 kb
File Type: zip
Download File

#include <iostream>
#include <string.h>
#include <windows.h>
using namespace std;


int CalGcd (int m, int n)
{
int result,temp,rem=1,gcd;


if(m>n){temp=m; m=n; n=temp;}
while(rem==1)
{
result=n%m;
if(result==0)
{
gcd=m; rem=0;
}
else
{
n=m; m=result;
}
}
return(gcd);



void main()
{


int x;

wcout <<  endl << "*** GCD ***" << endl;
wcout << "*************************************************" << endl;
int gcd = CalGcd (3265,31286);
cout << "GCD of (3265,31286) = " << gcd << endl;


cin >> x;
 }