### Write a C program to find the GCD of two given integers using non-recursive function

In this article, we will write a C program to find the GCD of two given integers using a non-recursive function.

GCD means Greatest Common Divisor. i.e the highest number which divides the given number.

Example: GCD(12,24) is 12

Formula: GCD= product of numbers/ LCM of numbers

# Algorithm:

Step 1: start

Step 3: call sub program g=GCD(a,b)

Step 4: print the g value

Step 5: stop

### Sub program:

Step 1: initialize the p=1, q, remainder

Step 2: remainder=p-(p/q*q)

Step 3: remainder=0 return q else goto step 4

# Write a C program to find the GCD of two given integers using 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
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();
}
``````

Output:

``````enter the two numbers whose gcd is to be found:5,25
GCD of a,b is : 5 ``````