Question:Find gcd of a number using recursion in c program 

Answer 
#include<stdio.h>
int main(){
  int n1,n2,gcd;
  printf("\nEnter two numbers: ");
  scanf("%d %d",&n1,&n2);
  gcd=findgcd(n1,n2);
  printf("\nGCD of %d and %d is: %d",n1,n2,gcd);
  return 0;
}

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;
}
 

+ Report
Total Preview: 488
Find gcd of a number using recursion in c program
Copyright © 2024. Powered by Intellect Software Ltd