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
- Language Skills (English): Vocabulary Verbal Analogy (Word Based Analogy) Noun Pronoun Verb Adjectives Adverb Preposition Articles Conjunction Tenses Modals Subject Verb Agreement (Verb Noun Agreement) Determiner Active Passive Voice (Voice) Direct and Indirect Speech Sentence Correction (Error Correction) Sentence Completion (Fill in the blanks) Sentence Construction Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing) Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions) Cloze Test (Cloze Passage)
- General Aptitude (Quantitative Ability): Percentage Ratio and Proportion (Ratios) Average Profit and Loss Simple Interest and Compound Interest Time and Work Pipe and Cistern Speed Time and Distance Mixture and Alligation Age Problems Partnership Number System HCF LCM Divisibility Rules Powers and Exponents (Surds and Indices) Algebra Data Interpretation Statistics Sequence and Series (Series) Logarithm Arithmetic
- General Aptitude (Reasoning Ability): Series (Number and Letter Series) (Numerical Relations and Reasoning) Coding Decoding Syllogisms Blood Relations Directions (Direction Test) Ranking, Order and Sequence Inequality Logical Sequence Of Words Seating Arrangements Puzzle Solving (Puzzles) Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning) Cubes & Dices Venn Diagram Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning) Selection Decision Table (Decision Making) Analytical Reasoning (Counting Figures Reasoning) Clock Calendar Data Sufficiency Analogy
- Technical Skills MCQ - Data Structure: Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing
- Technical Skills MCQ - 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 Application Layer Network Security
- Technical Skills MCQ - Operating System: Introduction to OS Process Management CPU Scheduling Process Synchronization Deadlock Threads & Process Creation Memory Management Virtual Memory File Management Windows OS Linux OS Security Virtual Machines
- Technical Skills MCQ - DBMS: Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) File Organization & Indexing Relational Algebra SQL Transaction Management Concurrency Control Database Recovery Database Security & Authorization NoSQL
- Technical Skills MCQ - Software Engineering: Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management
- Technical Skills MCQ - Cloud Computing: Cloud Computing and IoT
- Technical Skills MCQ - Cyber Security: Cyber and Info Security Security in Mobile and Wireless Computing
- Technical Skills (Coding): Coding Questions by Yash Sir C Programming by Yash Sir Programming in C++ Java Python for Placements by Yash Sir Object Oriented Programming (OOPS) DSA by Prashant sir Coding Questions Bank
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.

