Tuesday 24 July 2012

How to write C Program to calculate L.C.M and G.C.D of two numbers using function

Program source code

void gcd(int,int);

void lcm(int,int);


int main()

{

int a,b;


printf("Enter two numbers: \t");

scanf("%d %d",&a,&b);


lcm(a,b);

gcd(a,b);



return 0;

}


//function to calculate l.c.m

void lcm(int a,int b)

{

int m,n;


m=a;

n=b;


while(m!=n)

{

if(m
m=m+a;
else
n=n+b;
}

printf("\nL.C.M of %d & %d is %d",a,b,m);
}

//function to calculate g.c.d
void gcd(int a,int b)
{
int m,n;

m=a;
n=b;

while(m!=n)
{
if(m>n)
m=m-n;
else
n=n-m;
}

printf("\nG.C.D of %d & %d is %d",a,b,m);
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: