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.
Inside: a video lesson and guided study material.
Module outline
- Quantitative Ability: Speed Mathematics and Basic Mathematics, Percentage, Ratio and Proportion (Ratios), Average, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Speed Time and Distance, Number System, HCF LCM, Data Interpretation, Age Problems, Mixture and Alligation, Partnership, Algebra, Sequence and Series (Series), Mensuration and Geometry, Arithmetic
- Reasoning Ability: Puzzle Solving (Puzzles), Seating Arrangements, Coding Decoding, Blood Relations, Directions (Direction Test), Syllogisms, Data Sufficiency, Ranking, Order and Sequence, Series (Number and Letter Series) (Numerical Relations and Reasoning), Logical Sequence Of Words, Calendar, Clock, Cubes & Dices, Analytical Reasoning (Counting Figures Reasoning), Data Arrangement, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning)
- Verbal Ability: Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Cloze Test (Cloze Passage), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Vocabulary, Sentence Completion (Fill in the blanks), Active Passive Voice (Voice), Direct and Indirect Speech, Subject Verb Agreement (Verb Noun Agreement), Tenses, Preposition, Articles, Sentence Correction (Error Correction)
- Programming Basics (MCQs + Interview): C Programming by Yash Sir, Programming in C++, Java, Python for Placements by Yash Sir
- OOPs (MCQs + Interview): Object Oriented Programming (OOPS)
- DBMS (MCQs + Interview): Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Transaction Management, Decomposition Properties & 4NF, Concurrency Control, Database Recovery, File Organization & Indexing, Relational Algebra, Database Security & Authorization
- SQL (MCQs + Interview): SQL
- Operating Systems (MCQs + Interview): Introduction to OS, Process Management, CPU Scheduling, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Process Synchronization, Disc Scheduling, File Management, Security
- Computer Networks (MCQs + Interview): 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, Mobile Technology, Cloud Computing and IoT, Cyber and Info Security
- Coding: Coding Questions by Yash Sir
- HR Interview: MR & HR Interview Preparation
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
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: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.
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.