img
Question:
Published on: 22 December, 2024

What do you mean by recursion? Write down a C function to find out the GCD of two nos. using recursive technique.

Answer:

Recursion is a programming technique that allows the programmer to express operations in terms of themselves. In C, this takes the form of a function that calls itself.

 

C function to find out the GCD of two nos. using recursive technique.

#include <stdio.h>
int gcd(int n1, int n2);
int main()
{
   int n1, n2;
   printf("Enter two positive integers: ");
   scanf("%d%d", &n1, &n2);
   printf("G.C.D of %d and %d = %d", n1, n2, gcd(n1,n2));
   return 0;
}
int gcd(int n1, int n2)
{
    if (n2!=0)
       return gcd(n2, n1%n2);
    else 
       return n1;
}
Random questions