c program
C-programming with primitiveGCD function?
yeah, absolutely! Very good question. Shows a brilliant mind.
Reply:U haven't stated what do u need, recursive or non-recursive program. Since u've asked for primitive one, I think u need the Euclidean algo. for GCD.
//Prog. to get G.C.D. of two integers using Euclidean Algorithm
// ( without recursion )...................................
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
main()
{
int a,b,c,d ;
clrscr() ;
printf("\n Enter 2 integers ") ;
scanf("%d %d",%26amp;a,%26amp;b) ;
if( a%26lt;b )
{
a=a+b ;
b=a-b ;
a=a-b ;
}
while( a%26gt;b )
{
c=a/b ;
d=a-b*c ;
if( d==0 )
break ;
a=b ;
b=d ;
}
printf("\n Required G.C.D. of two entered nos. = %d ", b) ;
getch() ;
}
orchid cactus
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment