2 つの数値の GCDを計算するプログラム。
#include<stdio.h>
#include<conio.h>
int findgcd(int x,int y)
{
 while(x!=y)
 {
  if(x>y)
  {
   return findgcd(x-y,y);
  }
  else
  {
   return findgcd(x,y-x);
  }
 }
 return x;
}
void main()
{
 int n1,n2,gcd;
 clrscr();
 printf("\n GCD Calculator [ Please Enter Positive Integer number. ]\n");
 printf("\nEnter 1st numbers: ");
 scanf("%d",&n1);
 printf("\nEnter 2nd numbers: ");
 scanf("%d",&n2);
 if(n1>0 && n2>0)
 {
  gcd=findgcd(n1,n2);
  printf("\nGCD of %d and %d is: %d ",n1,n2,gcd);
 }
 else
 {
  printf("\n Sorry, Wrong Input.");
 }
 getch();
}
Cで再帰を使用して2つの数値のGCDを計算する別の方法はありますか.
または、再帰なしで、このプログラムを簡単な方法で書くにはどうすればよいですか?