Write a program to find LCM of two number
using function
Recursion recursion
using function
- #include <stdio.h>
- int gcd(int, int);
- int main() {
- int n1, n2, lcm_gcd, lcm;
- printf("Enter two numbers to find LCM : ");
- scanf("%d %d", &n1, &n2);
- lcm_gcd = gcd(n1, n2);
- lcm = (n1*n2)/lcm_gcd;
- //printf("\n%d and %d of GCD is = %d\n", n1, n2, lcm_gcd);
- printf("\n%d and %d of LCM is = %d\n", n1, n2, lcm);
- return 0;
- }
- int gcd(int n1, int n2) {
- if (n1 == 0) {
- return n2;
- }
- while (n2 != 0) {
- if (n1 > n2) {
- n1 = n1-n2;
- }
- else {
- n2 = n2-n1;
- }
- }
- return n1;
- }
Recursion recursion
- #include <stdio.h>
- int gcd(int, int);
- int main() {
- int n1, n2, lcm_gcd, lcm;
- printf("Enter two numbers to find LCM : ");
- scanf("%d %d", &n1, &n2);
- lcm_gcd = gcd(n1, n2);
- lcm = (n1*n2)/lcm_gcd;
- //printf("\n%d and %d of GCD is = %d\n", n1, n2, lcm_gcd);
- printf("\n%d and %d of LCM is = %d\n", n1, n2, lcm);
- return 0;
- }
- int gcd(int m, int n) {
- if (n == 0) {
- return m;
- }
- else {
- return gcd(n, m%n);
- }
- }
একটি মন্তব্য পোস্ট করুন