#include< conio.h>
int main( )
{
int a, b, temp, rem,
clrscr( );
printf("Enter the required two input values:");
scanf(" %d%d",&a, &b);
if(a==0)
{ printf("\nHCF of number is : %d", b );
goto last;
}
if(b==0)
{ printf("\nHCF of number is : %d", a );
goto last;
}
// Here i'm taking a empty 'for' loop
// means no initial, final and incre/decrement
for( ; ; )
{
rem=a %b;
if(rem==0) break;
a= b;
b= rem;
}
printf("\nHCF of Number is : %d", b);
last:
getch( );
return 0;
}
Output:-
Enter the required two input values: 49
47
HCF of number is: 1
I have copied your entire program into my software when i compile it and entered the two input values
ReplyDelete49 47 i was getting the answer as 1 ,,,... plz tell me why is it so.
can i do it using for loop?????
ReplyDeleteHEy dude.. try working the program for numbers 10 and 12
ReplyDelete#include
ReplyDelete#include
void main()
{
clrscr();
int a,b,c,z,ans;
printf("enter any value");
scanf("%d",&a);
printf("enter second value");
scanf("%d",&b);
printf("enter third value");
scanf("%d",&c);
printf("the common factors of these values are\n");
ans=1;
for(;ans<=a+b+c;ans++)
{
if(a%ans==0&&b%ans==0&&c%ans==0)
{
printf("%d\n",ans);
z=ans;
}
}
printf("the highest common factor is %d",z);
getch();
}
easy program to find HCF (GCD) between two numbers without using GOTO
ReplyDelete#include
int main()
{
int a,b,c,d,temp,j,hcf;
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
if(a>b)
temp=a;
else
temp=b;
for(j=1;j<=temp;j++)
{
c = a%j;
d = b%j;
if(c==0 && d==0)
hcf=j;
}
printf("HCF is %d",hcf);
return 0;
}
thnks 4 ur program
DeleteSimple HCF...program
ReplyDeletehttp://123techguide.blogspot.com/2012/01/find-hcf-using-c-program.html
thnks 4 the prgram
ReplyDeleteeasy program to find HCF (GCD) between two numbers without using GOTO
ReplyDelete#include
main()
{
int a,b,x,y;
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
x=a,y=b;
while(x!=0)
{
if(x>y)
x=x-y;
else
y=y-x;
}
printf("HCF of %d and %d is %d",a,b,x);
}