Write a recursive program to find GCD of two numbers.


This answer is not selected as best answer. This answer may not be sufficient for exam.

Your limit has been exceed. We have implemented this system because, We got difficulty on managing our servers. Please donate some amount to remove this limit.

Quota: 0 / 30

#include <stdio.h>

int hcf(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 is %d.", n1, n2, hcf(n1, n2));
    return 0;

int hcf(int n1, int n2) {
    if (n2 != 0)
        return hcf(n2, n1 % n2);
        return n1;

The output of above program is

Enter two positive integers: 366
G.C.D of 366 and 60 is 6.
If you found any type of error on the answer then please mention on the comment or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .