Find GCD or HCF of two numbers | User Given Number | C-Program
GCD or HCF:
Tips:
1.Take three variable.
2.Use conditional operator.
3.Use for loop for decrement the value.
4.Use if and break statement.
Code:
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter two number:\n");
scanf("%d%d",&a,&b);
for(c=a>b?a:b;c>=1;c--)
if(a%c==0 && b%c==0)
break;
printf("The GCD is %d\n",c);
getch();
}
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)