Find sum of digits in a given number
Duration: 4 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 educational video, presented by a lecturer from Knowledge Gate, teaches how to write a C program to find the sum of the digits of a given positive integer. The lesson begins with an introduction to the problem, Q12, which requires a program to take an integer as input and output the sum of its digits. The instructor then presents a C code solution using a while loop. The core logic involves repeatedly extracting the last digit of the number using the modulo operator (n % 10) and adding it to a running sum, then removing that digit by integer division (n / 10). The process continues until the number becomes zero. The video includes a step-by-step walkthrough of the algorithm with the example number 1234, showing how the sum is calculated as 1+2+3+4=10. The final segment demonstrates the code running in an online C compiler, confirming the correct output.
Chapters
0:00 – 2:00 00:00-02:00
The video opens with the 'KNOX MEEHEGATF' logo, which is a stylized version of 'KNOWLEDGE GATE'. It then transitions to a slide showing the 'KNOWLEDGE GATE' brand and its social media handles. The main content begins with a chalkboard-style presentation of a C program. The instructor, Yash Jain Sir, introduces the problem: 'Q12: Program to find sum of digits.' The problem statement specifies that the input is any positive integer and the output is the sum of its digits. Two public test cases are shown: for input 1234, the output is 10 (1+2+3+4), and for input 129487, the output is 31 (1+2+9+4+8+7). The instructor explains the problem and prepares to show the solution code.
2:00 – 4:17 02:00-04:17
The instructor displays the C code solution on the screen. The code includes the necessary header files, defines the main function, and initializes variables 'n' and 'sum'. The core logic is a while loop that continues as long as 'n' is not zero. Inside the loop, the last digit of 'n' is obtained using 'n % 10' and added to 'sum', and 'n' is updated by integer division 'n / 10'. The final sum is printed. The instructor then walks through the algorithm with the example number 1234, writing out the steps on the board: 1234 % 10 = 4, sum = 0 + 4 = 4, n = 1234 / 10 = 123; 123 % 10 = 3, sum = 4 + 3 = 7, n = 123 / 10 = 12; 12 % 10 = 2, sum = 7 + 2 = 9, n = 12 / 10 = 1; 1 % 10 = 1, sum = 9 + 1 = 10, n = 1 / 10 = 0. The loop ends, and the final sum of 10 is printed. The video concludes with a demonstration of the code running in the GDB online compiler, showing the correct output for the input 1234.
The video provides a clear, step-by-step tutorial on solving a common programming problem. It effectively combines a problem statement, a complete code solution, a detailed algorithmic walkthrough, and a live code execution to reinforce the learning. The progression from problem definition to practical implementation ensures a comprehensive understanding of the digit-sum algorithm, which is a fundamental concept in programming.

