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
- 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)
- 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
- 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)
- Section B | C Programming: C Programming by Yash Sir, Coding Questions by Yash Sir
- Section B | Data Structures: Algorithm Analysis, Greedy Algorithms, Time Complexity Analysis, Sorting Algorithms, Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs
- Section B | OOP (C++): Object Oriented Programming (OOPS), Programming in C++
- 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
- 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
- Section B | AI & Big Data Basics: AI & ML by Arun Sir, Big Data Systems
- 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
- 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
- MOCK 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.

