
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Program to find LCM of two Fibonnaci Numbers in C++
In this problem, we are given two numbers N and M. Our task is to create a program to find LCM of two Fibonacci Numbers in C++.
Problem Description − We will find the Nth and Mth Fibonacci number. And then we will find the LCM of their two numbers and return the result.
Fibonacci Numbers
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377....
Let’s take an example to understand the problem,
Input: N = 4, B = 9
Output:
Explanation
4th Fibonacci number is 2
9th Fibonacci number is 21
LCM is 42.
Solution Approach
To solve the problem, we need to find the Fibonacci Number of N and M. Then find the LCM of the number.
Example
#include <iostream> using namespace std; long int fibo(int N){ long int a=0,b=1,c; for(int i=2; i< N;i++) { c=a+b; a=b; b=c; } return c; } int findLCM(int a, int b){ int max, step, lcm; lcm = 0; if(a > b) max = step = a; else max = step = b; while(1) { if(max%a == 0 && max%b == 0) { lcm = max; break; } max += step; } return lcm; } int CalcFiboLCM(int N, int M) { int fiboN = fibo(N); int fiboM = fibo(M); return findLCM(fiboN, fiboM); } int main() { int N = 5, M = 14; cout<<"The LCM of two Fibonnaci number is "<<CalcFiboLCM(N, M); return 0; }
Output
The LCM of two Fibonacci number is 699
- Related Articles
- Java Program to Find LCM of two Numbers
- Swift Program to Find LCM of two Numbers
- Haskell program to find lcm of two numbers
- Kotlin Program to Find LCM of two Numbers
- Java program to find the LCM of two numbers
- Find LCM of two numbers
- Program to find last digit of n’th Fibonnaci Number in C++
- How to find the LCM of two given numbers using Recursion in Golang?
- C++ Program to Find the GCD and LCM of n Numbers
- GCD and LCM of two numbers in Java
- The product of two numbers is 1944 and their LCM is 108. Find the HCF of the two numbers.
- Find HCF and LCM of 404 and 96 and verify that HCF$×$LCM $ =$ Product of the two given numbers.
- C++ Program to Find LCM
- Java Program to Find GCD of two Numbers
- Swift Program to Find GCD of two Numbers

Advertisements