Find LCM of 2 Numbers

Duration: 4 min

This video lesson is available to enrolled students.

Return to /learn/CDAC-C-CAT-COMPLETE-PREPARATION/section-b-c-programming/coding-questions/coding-question/asset-find-lcm-of-2-numbers after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Section A | English: Vocabulary, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Preposition, Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Articles, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Verbal Analogy (Word Based Analogy)
  2. Section A | Quant Aptitude: Ratio and Proportion (Ratios), Mixture and Alligation, Permutation and Combination, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Arithmetic, Algebra, Powers and Exponents (Surds and Indices), Average, Age Problems, Percentage, Profit and Loss, Partnership, Time and Work, Simple Interest and Compound Interest, Mensuration and Geometry, Probability, Pipe and Cistern
  3. Section A | Reasoning: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Calendar, Clock, Blood Relations, Directions (Direction Test), Seating Arrangements, Ranking, Order and Sequence, Puzzle Solving (Puzzles)
  4. Section B | C Programming: C Programming by Yash Sir, Coding Questions by Yash Sir
  5. Section B | Data Structures: Algorithm Analysis, Greedy Algorithms, Time Complexity Analysis, Sorting Algorithms, Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs
  6. Section B | OOP (C++): Object Oriented Programming (OOPS), Programming in C++
  7. Section B | OS: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS
  8. Section B | Networking: Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics
  9. Section B | AI & Big Data Basics: AI & ML by Arun Sir, Big Data Systems
  10. Section C | Digital Electronics: Digital Systems & Boolean Basics, Logic Gates & Hardware, Boolean Expression, Boolean Minimization, Combinational Circuit, Sequential Circuits, Number System, Number Representation, Analog-Digital Conversion
  11. Section A, C | Comp. Fundamentals, COA: Basics of COA, Floating Point Rep, Cache Memory Organization, Input Output Organisation, Pipelining, Instr Formats & Modes, Control Unit Design, Register Transfer and Microoperations, Multiprocessors, Programming the Basic Computer
  12. MOCK TEST:
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This educational video, presented by a 'Placement Expert' from Knowledge Gate, teaches how to find the Least Common Multiple (LCM) of two numbers using programming. The lecture begins by defining the problem and providing sample input-output pairs. It then explains the mathematical logic of LCM using prime factorization, demonstrating the method with the numbers 15 and 25. The video transitions to a more efficient algorithm based on the formula LCM(a, b) = (a * b) / GCD(a, b). The core of the lesson is a step-by-step walkthrough of a C program that implements this solution, including a recursive function for calculating the Greatest Common Divisor (GCD) and a main function that takes user input and prints the result.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The video opens with the Knowledge Gate logo, followed by a slide showing the organization's various educational channels. The main lecture begins with a problem statement on a digital blackboard: 'Q6: Write a program find LCM of two numbers'. The instructor, identified as 'Yash Jain Sir', presents sample inputs and outputs, such as Input: 15 20, Output: 60, to clarify the expected behavior. The core concept is introduced with the definition 'LCM = Smallest Number that divides both'. The logic is explained using prime factorization, with the example of 15 and 25. The prime factors of 15 are 5 and 3, and for 25 are 5 and 5. The LCM is found by taking the union of all factors, which is 5, 5, and 3, resulting in 75. The instructor emphasizes that the LCM is the product of the union of all prime factors.

  2. 2:00 – 3:37 02:00-03:37

    The video transitions to a more efficient algorithm for finding the LCM. The instructor states that a simple solution is to find the prime factors and take their union, but an efficient solution uses the formula LCM(a, b) = (a * b) / GCD(a, b). The formula is written on the board, and the instructor explains that the GCD (Greatest Common Divisor) is the key to this method. The lesson then shifts to a C code implementation. A code snippet is displayed, showing the inclusion of the stdio.h header and the definition of a recursive function `int gcd(int a, int b)` which uses the Euclidean algorithm. The `int lcm(int a, int b)` function is shown to calculate the LCM using the formula. The `main()` function is presented, which takes two integers as input, calls the `lcm` function, and prints the result. The instructor then demonstrates the GCD calculation for a=6 and b=12, showing the recursive steps: `gcd(6,12)` calls `gcd(12%6, 6)` which is `gcd(0,6)`, and since a=0, it returns 6. This GCD value is then used to calculate the LCM.

The video provides a comprehensive, step-by-step guide to solving the LCM problem. It starts with a conceptual understanding of LCM using prime factorization, which is a fundamental but less efficient method. It then introduces a more practical and efficient algorithm based on the mathematical relationship between LCM and GCD. The core of the lesson is the implementation of this algorithm in C, with a clear, well-structured code example that includes a recursive GCD function. The instructor effectively bridges the gap between mathematical theory and programming practice, making the concept accessible for students preparing for coding interviews.

Loading lesson…