Friday, March 20, 2015

Natural numbers on c program



#include 
int gcd (int a, int b) 
{
  int temp;
  while (b != 0) 
{
    temp = a % b;
    a = b;
    b = temp;
  }
  return(a);
}
 
int main () 
{
  int x, y;
  cout << "Enter two natural numbers: ";
  cin >> x >> y;
  cout << "gcd(" << x << ", " << y << ") = " << gcd(x,y) << endl;
  return(0);
}
 

No comments:

Post a Comment