Wednesday, 10 April 2013

c program to find the GCD of two given integers by using the non recursive function




#include<stdio.h>
#include<conio.h>
#include<math.h>
int gcdnonrecursive(int m,int n)
{
            int remainder;
            remainder=m-(m/n*n);
             if(remainder==0)
            return n;
             else
             return gcdnonrecursive(n,remainder);
}

void main()
{
             int a,b,igcd;
  clrscr();
             printf("enter the two numbers whose gcd is to be found:");
            scanf("%d%d",&a,&b);
            printf("GCD of %d",gcdnonrecursive(a,b));
                                     getch();
}

No comments: