 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So in this video, I'm going to explain how you can calculate some of the visits of a number, right? So before starting, I want to share some details. So if you go to the details or description of this video, you will find links of various pages related to various programming languages. So if you want to watch more programming related videos, you can follow those updates. Now I'm going to start this. So first I'm going to explain the scenario like what we are going to interpret. So let's say we have a number 1, 2, 3, right? So now what we need to calculate? We need to calculate this 1 plus 2 plus 3. So we need to add each digit. Those are available in this number separately. And then the final outcome will be the output. So 1 plus 2 plus 3 is equal to 6. So if we take input as 123, so its output should be 6. Now if we take input as 12, so its output will be 3. If we take number as 1234, so its output will be 10. So no matter how many digits are available in a number, the program should work for all numbers. So it should work for 123 as well because it is 3 digit number. The program should work for this as well because it is 2 digit number. Then for it as well because it is 4 digit number. So we need to separate each digit from that number. And then we need to add those digits so that we can find out the final outcome. So this is the mathematical explanation. Now I am going to convert this calculation into C program. So here you can see I have declared 3 variables N, S and A. S is initially initialized with 0. Then I am writing print test. So print test will display the masses and the number. And I am going to receive that number into a variable N. Now I am going to apply a Y loop so that we can implement this logic. So Y condition is N greater than 0. And inside this loop I am going to write 3 statements. So let me first write those. Then I will explain how they are working. So first is this N modulus N. Then S equals to S plus A. Then N equals to N by N. And this way I completed this Y loop. So now I am going to explain this how it is working. So let's take example of 120 people. Then I will be taking example of 12. And then you will automatically understand how 1234 will be calculated. So initially N is 123. Value of S is 0. So let's check this condition. N is greater than 0. Now N modulus 10. So 123 modulus 10. So remainder will be 3. So whenever you divide any number with 10. So remainder will be always last digit of that number. So in this case number was 123. We are dividing it by 10. So remainder will be 3 automatically. And we are storing that into A. Now I need to add this digit into S. So this is very simple. So S is currently 0. We are adding A that is 3. So 3 plus 0 will become 3. So new value of S is now 3. Now calculate this N divided by 10. So N is 123. If we divide 123 by 10. So result will be 12. Because if we divide any number with 10, let's say 123. So its result will be 12.3. And we are using integer as data type. So it will store on 12. So first rotation of loop is completed. Now we need to check the condition again. So right now N is 12. So 12 is greater than 0. It is true. Now check this. 12 modulus 10. So 12 modulus 10, remainder will be 2. And that will be stored inside A. Now see the current value of S that is 3. Add A that is 2. So 3 plus 2 will be 5. So 5 will be stored inside S. Then again we need to divide 10 by 10. So N is 12. So next time it will be 1 only. Because 12 by 10 will become 1.2 and we need to store on the 1. Because we are taking variable size of integer type. So second rotation is completed. Now again check the condition. So N is 1. So 1 is greater than 0. Then 1 modulus 10. So in case of modulus operation if numerator is less than as compared to denominator. So final outcome will be numerator value as it is. So A will be having 1. Now S is 5. And we need to add A that is 1. So 5 plus 1 will be 6. So new value of S will become 6 now. Now divide N by 10. So if we divide 1 by 10. So result will be 0 point something. So we need to store 0 into N. So third rotation is completed. Now check the condition. N is 0. So 0 greater than 0 is false. So this way you saw if number is of 3 digit. So this loop will repeat 3 times only. If number is of 2 digit this loop will repeat 2 times. If number is having 4 digits. So this loop will automatically repeat 4 times. So I hope now you can calculate the sum of these 2 values as well. Because I explained you the complete rotation of this loop. So here this statement is important which is calculating sum of individual digits. Now after completion of this loop we can print value of S that is containing final outcome. So after completion of this loop you can write print F sum equals to percent D comma S. So this way it will be printed and then I am closing main function. So here you can see this loop is calculating sum of individual digits. And then after completion of this loop we are printing value of S variable so that outcome can be displayed on output screen. So I hope you understood how I calculated logic first and then how I implemented the program with N form C. So if you want to watch more programming related videos you can open my channel and go to playlist so there are various programming related videos are available. So I have uploaded more than 1000 videos on my YouTube channel. So you can watch them and you can learn programming easily. So I hope you understood whatever I explained in this video. Thank you for watching this video.