Users Online
· Guests Online: 104
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C Program to Find LCM of a Number using Recursion
The following C program, using recursion, finds the LCM. An LCM is the lowest common multiple of any 2 numbers.
Here is the source code of the C program to find LCM of a Number using Recursion. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Find LCM of a Number using Recursion
*/
#include <stdio.h>
int lcm(int, int);
int main()
{
int a, b, result;
int prime[100];
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
result = lcm(a, b);
printf("The LCM of %d and %d is %d\n", a, b, result);
return 0;
}
int lcm(int a, int b)
{
static int common = 1;
if (common % a == 0 && common % b == 0)
{
return common;
}
common++;
lcm(a, b);
return common;
}
$ cc pgm22.c
$ a.out
Enter two numbers: 456
12
The LCM of 456 and 12 is 456
$ a.out
Enter two numbers: 45 75
The LCM of 45 and 75 is 225
Here is the source code of the C program to find LCM of a Number using Recursion. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Find LCM of a Number using Recursion
*/
#include <stdio.h>
int lcm(int, int);
int main()
{
int a, b, result;
int prime[100];
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
result = lcm(a, b);
printf("The LCM of %d and %d is %d\n", a, b, result);
return 0;
}
int lcm(int a, int b)
{
static int common = 1;
if (common % a == 0 && common % b == 0)
{
return common;
}
common++;
lcm(a, b);
return common;
}
$ cc pgm22.c
$ a.out
Enter two numbers: 456
12
The LCM of 456 and 12 is 456
$ a.out
Enter two numbers: 45 75
The LCM of 45 and 75 is 225
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.