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
- TCS One Shot Free Videos & Notes: TCS Preparation
- Numerical Ability (Foundation Section): Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Algebra, Probability, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Mensuration and Geometry, Mental Ability, Age Problems, Statistics, Arithmetic, Partnership, Speed Mathematics and Basic Mathematics
- Reasoning Ability (Foundation Section): Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Directions (Direction Test), Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Calendar, Clock, Cubes & Dices, Selection Decision Table (Decision Making), Crypt Arithmetic, Venn Diagram, Data Arrangement, Inequality, Analogy, Ranking, Order and Sequence, Logical Sequence Of Words
- New Pattern-Verbal Ability (Foundation Section): Sentence Completion (Fill in the blanks), English Writing Ability
- Old Pattern-Verbal Ability (Foundation Section): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Articles, Direct and Indirect Speech, Conjunction, Modals, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Verbal Analogy (Word Based Analogy), Active Passive Voice (Voice), Determiner, Facts, Inference and Judgements, Adverb, Cloze Test (Cloze Passage), Sentence Construction, Verb
- Advanced Quantitative Ability: TCS NQT Advanced Quantitative Ability
- Advanced Reasoning Ability: TCS NQT Advanced Reasoning Ability
- Advanced Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Python for Placements by Yash Sir, DSA using Python, Object Oriented Programming (OOPS), Programming in C++, Java
- TCS Full Length Mock Test:
- TCS Interview & Resume Prep: MR & HR Interview Preparation, TCS Interview Preparation, Mock Interview, Interview Recordings, Resume Preparation, Resume Review
- Mega Test:
- Grand Test:
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.

