Greatest common divisor of two non-negative numbers
#include<stdio.h>
//main function
main ()
{
int u, v;
printf("\nEnter the two numbers to find GCD.\n");
scanf("%d%d",&u,&v);
gcd(u,v);
getch();
}
//calling function
gcd(u,v) //gcd(u,v) being called by main function
{
int temp;
printf("The gcd of %d and %d is ",u,v);
while(v!=0)
{
temp=u%v;
u=v;
v=temp;
}
printf("%d\n",u);
}
Comments
Post a Comment