**C Program to Find GCD and LCM of Number using Function****:**

If you are using any software then below program will not give an error, but if you are using **TURBO C** then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h> main() { int a,b; int lcm(int,int); int gcd(int,int); printf("Enter two numbers to find LCM and GCD\n"); scanf("%d%d",&a,&b); printf("GCD of %d and %d is %d\n",a,b,gcd(a,b)); printf("LCM of %d and %d is %d\n",a,b,lcm(a,b)); } int gcd(int a,int b) { int temp=0,gcd; while((b%a)!=0) { temp=b%a; b=a; a=temp; } return(a); } int lcm(int a,int b) { int temp=0; temp=a*b/gcd(a,b); return(temp); }

OUTPUT:

Enter two numbers to find LCM and GCD 10 45 GCD of 10 and 45 is 5 LCM of 10 and 45 is 90

Not understood

You must focus on the GCD process. For GCD we have check that MOD of 2nd and 1st number is not equal to zero. If it is zero then the loop will not work and will get answer as it is.

We have use the logic of swapping. You must try it at least one you will surely get your answer after implementing it properly.