Friday, 23 September 2016

GCD by Recursion

/* greatest common divisor by recursion */
#include<stdio.h>
int gcd(int,int);

int main()
{
int a,b;
printf("Type 2 values to find GCD :\n");
scanf("%d %d",&a,&b);
printf("GCD : %d",gcd(a,b));
return 0;
}

int gcd(int m,int n)
{
if(n>m) return gcd(n,m);
if(n==0) return m;
return gcd(n,m%n);
}

 

No comments:

Post a Comment

Featured post

Will AI Replace Programmers? The Truth Behind the Hype in 2025

Exploring the Future of Coding: Will AI Take Over Software Development or Enhance It?  Will AI Replace Programmers? The Truth Behind the Hyp...