Write a program to evaluate GCD of two given integers. Use function that returns GCD.

#include<stdio.h>
int gcd( int , int );
int main()
{
int x,y;
printf("enter any two integers:");
scanf("%d%d", &x,&y);
printf("the gcd of %d and %d is %d",x,y,gcd(x,y));
}
int gcd(int n1, int n2)
{
 int i,gcd;
 for(i=1;i<=n1 && i<=n2;i++)
 {
  if(n1%i==0 && n2%i==0)
  gcd=i;
 }
 return(gcd);
}

Comments

Post a Comment

Popular posts from this blog