GCD of two numbers in C programming|Learnerspage

0
47

#include<stdio.h>

int main()
{
int num1,num2,i,big,small,flag=0;
printf(“Enter ant two number: “);
scanf(“%d%d”,&num1,&num2);
big=(num1>num2)?num1:num2;
small=(num1<num2)?num1:num2;

for(i=small;i>=1;i–)
{
if(big%i==0 && small%i==0)
{
printf(“The GCD of %d and %d is %d”,num1,num2,i);
break;
}
flag++;
}
if(flag>small)
{
printf(“The GCD of %d and %d is 1”,num1,num2);
}
return 0;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here