Check if a number is divisible by 3 or 5 or both using Programming

Duration: 6 min

This video lesson is available to enrolled students.

Return to /learn/LTI-MINDTREE-PREPARATION/coding/programming-in-c/c-by-yash-sir/asset-check-if-a-number-is-divisible-by-3-or-5-or-both-using-programming after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. English Comprehension/Verbal Ability: Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions) Vocabulary Sentence Correction (Error Correction) Sentence Completion (Fill in the blanks) Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing) Subject Verb Agreement (Verb Noun Agreement) Tenses Verb Articles Preposition Conjunction Pronoun Noun Adjectives Adverb Modals Cloze Test (Cloze Passage) Active Passive Voice (Voice) Direct and Indirect Speech Sentence Construction
  2. Logical Ability: Coding Decoding Directions (Direction Test) Analogy Inequality Data Sufficiency Series (Number and Letter Series) (Numerical Relations and Reasoning) Syllogisms Seating Arrangements Puzzle Solving (Puzzles) Blood Relations Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning) Ranking, Order and Sequence Logical Sequence Of Words Data Arrangement Venn Diagram Calendar Clock
  3. Quantitative Ability: Logarithm Permutation and Combination Probability Profit and Loss Speed Time and Distance Mixture and Alligation Partnership Simple Interest and Compound Interest Percentage Ratio and Proportion (Ratios) Average Time and Work Pipe and Cistern Number System Divisibility Rules HCF LCM Algebra Powers and Exponents (Surds and Indices) Mensuration and Geometry Age Problems Data Interpretation Sequence and Series (Series)
  4. Basic Analytical Ability: Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning) Analytical Reasoning (Counting Figures Reasoning) Cubes & Dices Selection Decision Table (Decision Making)
  5. Computer Programming: Pseudo Codes Coding Questions by Yash Sir C Programming by Yash Sir Programming in C++ Java Python for Placements by Yash Sir
  6. DBMS (Computer Science): Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) Transaction Management Concurrency Control Database Security & Authorization
  7. SQL (Computer Science): SQL
  8. OS (Computer Science): Introduction to OS Process Management CPU Scheduling Deadlock Process Synchronization Threads & Process Creation Memory Management Virtual Memory File Management
  9. Computer Networks (Computer Science): 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 Network Security
  10. Data Structures (Computer Science): Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing
  11. OOPs (Computer Science): Object Oriented Programming (OOPS)
  12. Software Engineering (Computer Science): Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management
  13. SVAR Conversational - Spoken English: Communication Assessment
  14. HR Interview: MR & HR Interview Preparation
  15. Coding Practice Questions: Coding Questions Bank
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This video is a coding tutorial demonstrating how to write a C++ program to check if a number is divisible by 3 or 5 or both. The instructor, Yash Jain, presents a complete program in an online IDE, explaining the logic and syntax. The core of the program uses the modulo operator (%) to check divisibility. The condition `if (n % 3 == 0 || n % 5 == 0)` evaluates to true if the number is divisible by 3, by 5, or by both, and the program outputs a corresponding message. The instructor walks through the code, highlighting the `if-else` structure and the logical OR operator (`||`). The video concludes with a demonstration of the program's execution, showing the output for a test case where the input is 3, which is divisible by 3, resulting in the message 'Given number is divisible by 3 or 5 or both'.

Chapters

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

    The video opens with a C++ code editor displaying a program titled 'Finding if a number is divisible by 3 or 5 or both'. The code includes standard C++ headers and a main function. The instructor explains the program's purpose and begins to write the code, starting with the `#include <iostream>` and `using namespace std;` statements. He then defines the `int main()` function and declares an integer variable `n`. The next step is to prompt the user for input with `cout<<"Enter the number: ";` and read the value with `cin>>n;`. The core logic is introduced with an `if` statement: `if(n % 3 == 0 || n % 5 == 0)`, which checks if the number is divisible by 3 or 5. The instructor explains that the `||` operator means 'or', so the condition is true if either part is true. The program then outputs a message if the condition is met, and an alternative message if it is not, using an `else` clause.

  2. 2:00 – 5:00 02:00-05:00

    The instructor continues to explain the program's logic, focusing on the `if` condition `if(n % 3 == 0 || n % 5 == 0)`. He emphasizes that the modulo operator `%` returns the remainder of a division. If the remainder is 0, the number is divisible. He explains that the condition will be true if the number is divisible by 3, by 5, or by both. He then demonstrates the program's execution by running it. The console output shows the prompt 'Enter the number:'. The instructor types '3' as the input. The program evaluates the condition: `3 % 3 == 0` is true, and `3 % 5 == 0` is false. Since the logical OR (`||`) only requires one condition to be true, the entire expression is true. The program executes the `if` block and prints 'Given number is divisible by 3 or 5 or both'. The instructor then shows the program's output in the console, which also displays '...Program finished with exit code 0' and 'Press ENTER to exit console.' He briefly mentions that the condition can be written as `if(n % 3 == 0 || n % 5 == 0)` and that the `||` operator is a logical OR.

  3. 5:00 – 5:47 05:00-05:47

    The instructor concludes the tutorial by summarizing the key concepts. He reiterates that the program uses the modulo operator to check for divisibility and the logical OR operator to combine two conditions. He confirms that the program correctly identifies numbers divisible by 3, 5, or both. The final code is shown in the editor, with the `if` condition `if(n % 3 == 0 || n % 5 == 0)` and the corresponding `cout` statements. The video ends with the instructor's final remarks, and the screen shows the completed code and the successful execution output for the input 3.

The video provides a clear, step-by-step tutorial on implementing a fundamental logic problem in C++. It begins by establishing the necessary C++ syntax and then focuses on the core algorithm: using the modulo operator to check divisibility and the logical OR operator to combine conditions. The instructor effectively demonstrates the program's logic and then validates it with a live run, showing the correct output for a test case. The progression from code writing to execution provides a complete learning experience for a beginner.

Loading lesson…