 Hello everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So this is day 6 of C and C++ coding bootcamp. And I hope you are doing good. And today I will be discussing four problems in front of you. With the help of those, I will guide you how you can build logic. So in the last two sessions, we discussed about operators. So in continuation with that, the problems will be similar like we discussed yesterday. And today's session will be a little bit short because I have those four programs only for today. And from next week, Monday onwards, we will be discussing about conditional statements. Right. So I'm going to start my session. So I'm just waiting for a couple of more minutes so that more folks can join. Okay, so those who are joining live, can you please confirm, am I audible properly? Like, are you able to listen to my voice? So if someone confirms so that I can proceed further. Okay. Thank you, Shivang for confirming. Okay, so moving forward like I hope those who are joining live or if you're watching the recording and like you are for the first time on this channel and you want to know about me. So with the help of this slide, you will be able to understand me. So I'm founder of Sanjay Gupta Tech School doing some like live sessions here and soon I will be starting some offline sessions as well. So I've been doing 16 plus years of experience, which is a mix of education industry plus IT industry and helping students, freshers and professionals to ramp their career in Salesforce ecosystem. So I saw like lots of folks who are from non-technical background. They're struggling in understanding coding. So that's why I started this bootcamp. And this bootcamp is also for BTEC student. So BTEC student, those who are starting their journey. So in their first year, they need to learn C and C++ programming. So this bootcamp will be helping those as well. Okay, so do consistent like be consistent and do regular practice, whatever I am explaining here. So this is a telegram group for this bootcamp C and C++ and anytime if you have any question, you can scan and ask questions there. So follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram and telegram and all the important links are available in the description of the video. So we'll be understanding how to build logic with the help of C programming. So I have these problems for you that we'll be discussing. So first problem says like we have a three digit number and we need to print some of its individual digits, right? So I'm going to solve this for you and then one by one we'll be solving each and every program. Okay, so first question is like number will be having three digits and we need to print some of its individual digits. And those who don't know like I have added an exercise sheet here. So if you click here, so you will find a link if you open this. So here you will find day wise exercises. So I have mentioned there those exercise in this sheet as well. But going forward, I will be having those exercise in that sheet only. Okay, so moving to the compiler. Okay, so I'm going to explain the whole concept again. So if you missed yesterday's session and if you want to understand this concept again, so you are welcome. So we have a num variable num and here I am assigning a number 123. Okay, so as per the question like question says we need to have a three digit number. So I right now I am just assigning this number into num variable, but here it is mentioned we need to read. So further I will be modifying this code and we'll be having printf scanf so that we can receive some input from the user and basis on that we can perform some calculation. So what we need to do, we have a number 123 so we just need to separate out one, two and three. So one should be separate, two should be separate and three should be separate. Right. So how we can do that. So here I'm going to use a variable a. Okay, so here we'll be using this statement a equals to num modulus 10. So can anyone tell me like what what would be the output of this like what will be the value inside a if we perform num modulus 10. And I already told you modulus operation we use for remainder purpose. So num is 123. We are dividing it by 10. So what should be the remainder? So can you please answer in the chat so that I can verify. Those who are watching life, please answer in the chat so that I can verify your answer and then I can proceed further to write another statement. So here we are dividing num by 10. So num is 123 we need to divide it by 10. So what should be the remainder? So my my saying 23. So anyone else who wants to answer to this question. So guys, this is this this session is for like building your logical skills. So please participate and answer in the chat so that I can verify your answer. So like if we divide any number by 10. So basically here in this case remainder will be three not 23. Right because you will be dividing it first time. So it will be divided by one time right then next time it will be divided by two times or remainder will be three not 23. Okay. So if you divide 123 by 10, so remainder will be three. So 123 will be divided by by 10 12 times. So quotient will be 12 and remainder will be three. Okay. So in a we are storing three. Now what I'm going to do I'm writing this statement. So can you tell me what should be the value inside num variable? So here what we are doing we are dividing num by 10. So right now we have division operator. We don't have modulus operator. We have a division operator. So can anyone tell me what should be the value in num? Like when we perform this operation. So what will be storing in num variable? So I'm just waiting for your answer so that I can verify and yep. So this time may my your answer is correct. It will be 12. So whenever we divide any three digit number by 10. So actually it should be 12.3. But here we are using data type as integer. So point three will be removed and only 12 will be assigned into num variable. So Rajiv your answer is also correct Rajesh your answer is also correct. So num will be having 12. So here a is three and num is having new value as 12. Okay. Now I'm going to create one more variable B. So B equals to num modulus 10. So now can anyone tell me what should be the result? What should be the value inside B? So num modulus 10. So we need to add it. We need to identify the value inside B. So please respond in the chat so that I can confirm your answer. So I need to know the value. So we are dividing num by 10. So here operator is modulus. So Rajiv says to Maima says to yeah. So answer is correct. So B B will be having value as two. So this is correct answer B will be having value as two. So why so because because num is having current value as 12. So after line number eight in line number nine num will be having the value as 12. So if you divide 12, so remainder will be two. Now I'm going to have one more variable C. So I'm writing C equals to num divided by 10. So can you tell me what should be the value inside C? So we are dividing number 10 and we need to identify the quotient value. So can you tell me the result that will be available inside C? So we need to identify the result of C or like now if you are pasting the answer. So just write the variable as well like B equals to what C equals to what so that I can see like which which for which variable you are telling the answer. So Sanketh is saying one Rajesh is saying C equals to 12. So anyone else who can answer this question. Rajeev is also saying one. Yes. So basically this num variable is having value as 12. So if we divide 12 by 10, so its result will be 1.2. But as we have all the variables of type integer, so the result will be one only. Right. It should be one only not 12. So here it is one. Right. Now what is the problem? Problem says read a three digit number and print some of its individual digits. So now we need to calculate some. So here if you see the comment section, so in the in the comments what you see A is three B is two and C is one. So number was 123. That's why here we are having three separate values. So now what I can do, I can take some as a variable and I'm writing some equals to A plus B plus C. Right. And here I can write print F. Person D and then some. So this way 123 some will be six. So when I execute this when I will be executing this program. So the result will be six. So I'm just clicking on this run button. And if I go below. So here you will see some is six. So an output result is showing as six. Okay. So this way I hope you understood this logic. Now one more time we are going to practice this. So I'm just going to going to erase these values. And here instead of 123, I'm writing this number 396. So num is having 396. Now you need to tell me what should be the value of A? What should be the value of num? What should be the value of B? What should be the value of C? And what should be the value of some? So these five variables value you need to paste in the comment section. Or like in the chat section. Right. So a question is number is 396. And you need to solve this equation. So if you are able to identify correct answers, so it means you are able to understand this logic properly. And this is important for beginners. So please do proper practice of this, whatever I am explaining. So and anytime like if you if you want to implement any code so you can just use online compiler and you will be able to type. So if you are pasting in the chat, so just write equals to this num equals to this. And so on like socket typed C1 A3 B2. So similar way you just need to type result of five different variables. So I'm just waiting for your answer then we'll be jumping to the next problem so that we can see like how we can solve that problem. Let's see who answers first. Okay, so I got one answer. Badal say Badal says A6 num 39 B9 C3. So let's see other answers as well. Then I will be solving it for you so that we can see which one is correct. So guys solve it quickly and write your answer in the chat so that I can compare whether it is correct or not. So I can see only one answer as of now. So I need more answers. So please type in the chat, whatever is your answer. So socket is saying A6 B9 C3 num 39 some 18 yard. So I think Badal socket your answers are matching. So I think it is correct. So I am just solving it for you. So num is your Mahima your answer is also seems to be correct. So num is 396. So if we divide it by 10, so remainder will be six. So A is six. Then we are dividing num. So 396 if we divide it by 10, so num will be 39. Right, because after decimal point six will be there and we can just remove that. And right now num is 39. So if we divide 39 with 10, so remainder will be nine. And if we divide num like 39 by 10, so quotient will be three. So these are the values A6 B9 C3. And if we calculate the sum, so it will be 18. Right, so I hope this way you are able to understand how we implemented this logic. Okay, so if you have any doubt you can ask in the chat. Otherwise, you can jump to the next question. So next question says, read a three digit number and print reverse of it. So can anyone tell me what should I do? So you can type your response in the chat. So can I reuse this program? So if I modify a little bit this program, will I be able to solve the second point? Or I need to write net new program. And you can write your answers both in Hindi, English, whatever is feasible to you. So just let me know what I need to change or do I need to write a new code to solve this problem? So I'm showing you the question again. So we are we are solving second question that is read a three digit number and print reverse of it. So number will be having three digits and we need to display its reverse. Right. So this is the problem that we need to solve. So I'm just waiting for your response like can we reuse this code or we need to implement it once again. And till the time you are trying it. So what I'm going to do here I'm writing printf scanf so that I can show you like if we receive some number from user. So then also this code will work. Right. So here I'm removing it. Or maybe just use it. So if I run this code now, so I need to enter a three digit number. So if you are watching on the screen, so just I'm just clicking on run and in the output you can see it is asking for a three digit number. So I'm entering 254. So you can see its result is 11, which is correct. 2 plus 5 plus 4 is 11. So as per the input now this code will be calculated. Okay, so make sure you enter a three digit number. If you enter two digit, one digit or four digit number, then output will be wrong because this code we implemented for three digit only. Right. So right now I'm making these statements as comment because I showed you this for your reference. Okay, so there are three responses. Maima's first response is correct. She deleted abhiram divide num by 100. No, this is not correct approach. Now next approach of Maima is correct. Like a will be multiplied by 100 B will be multiplied by 10 and plus C. So what we need to do we have 396. So we need to print 693. Right. Output should be 693. So here we need to calculate reverse. So I'm changing name of variable. It should be reverse. Right. So you can see last digit we have in a so what we can write a multiplied by 100. Then we have B B is having second digit so that we can multiply with 10 and then first digit we have in C. So that will be available in the last position. Right. So now if we calculate the reverse, so it will be showing 693. It will be showing 693. So if if we modify this statement like this and rest of the code will remain same. So you will be able to have the reverse of the number. And now if I run this code so you will see the reverse. Okay. So here I also need to change so you can see at bottom it is showing an error like this line number. 15 is having error. I used some but I need to use reverse. So I modified if I execute it now. So it will give me correct result. So result is 693. And the initial value was 396. So this way if we modify this code so it will give you the reverse. And one more thing Rajiv is also correct. So if you write this code like the highlighted code in place of this reverse variable. So that is also correct. So I'm cutting it from here and I'm writing it directly here so I can remove this variable. So this is also possible. So in this case you can remove that variable. So calculations will be same for three digit number. And then you just need to put this logic in the printf and your result will be available. Okay. So this time like if I change this I am putting some something else 365 and I'm clicking on run. So 563 is the result which is the reverse of that number. Okay. So I hope this way you are understanding this. Now we have two more problems. So next we need to solve it for four digit number and both like some of individual digits of four digit number. And we need to print reverse of a four digit number. Right. So just implement it. So yesterday I showed you two digit number solution. Today I am already done with three digit number. Now you will be having a four digit number. Let's say your number is this 3657. So first of all what you need to do you need to display some of this number. Three plus six plus five plus seven. So we just need to modify this code and then you will be able to solve it. So I am giving you a few seconds or minutes and just try to solve it. Maybe you can just open an online compiler and you can just write the code and you can just copy and paste that code in the chat. And if anybody is having any doubt in this code which I already explained so you can ask. So I would be happy to help you. Right. And I hope everybody understood the requirement that we are going to solve. So input number will be having four digits and we need to print some of its individual digits. So let's see who solves it first. So this this session is for logic checking logic building ability. So now I gave you a problem and that problem you need to solve yourself. And three digit problem I already solved. So I expect you will be solving and my eye in is in the chat. So I am seeing like who will be solving it for the like first. So take your time. Take your time if you have notepad so you can solve it there. If you have joined through laptop so you can open online compiler and you can quickly solve it. And I just need the middle code modified code because this code will be working for three digit only. So I want to know like how you will be modifying this code. So can can you confirm like who who is solving this. So can you type yes in the chat so that I can wait. So just type yes like if you are solving so that I can wait. Otherwise I will be solving it for you. Anyone who who joined live solving this respond guys. I am I am here for you only. So if if you are live so just just say yes you are solving. Yeah my my solving. So who else is solving. Please interact and I'm liking these live sessions. I was not sure like people will be interacting with me. So in today's session it was great like people responded. So Rajesh is also solving so it is good. So I'm sure like soon many folks many folks will be attending these live sessions because I am doing these sessions interactively. So if you are solving and I'm waiting and then I will be checking your answer. So from next week onwards like more interesting sessions will be there. We'll be focusing on conditional statements which is directly used in C++ Java and Apex programming. So if you want to become expert in programming so these C and C++ classes are very much important for you. Right so just do all the practice so that you can understand. So I'm just waiting for the responses so I can see Mahima and Rajesh two folks are solving. So yeah Abhiram answered. So yeah Abhiram you first divided by 1000 then divided by 1000 then divided by 10 then modulus 10. So you use 1010 to two values to divide in modulus so anyone else like any simple way. So yesterday I solved two-digit problem using 10. Today I solved three-digit problem using 10. So I want like you solve four-digit problem with this 10 only. So there may be two three more statements will be there but it would be a generic solution because in further in future we will be implementing a loop. We will be implementing a repetition. So through that repeat repetition like if you provide any digit number so that numbers some or reverse will be calculated automatically. So anyone who came up with the solution Mahima Rajesh or Rajeev if you are there so anyone who can solve it otherwise like I am just waiting for one more minute. Okay Abhiram so if you know the 10 like divide divide by 10 steps so I think that would be good so just try that. Okay so now I am going to solve it for you. So we have a number 3657 so first statement will be same. We need to divide number by 10 so remainder will be 7 here right remainder will be 7 then we need to divide number by 10 so it will be 365 right. So if you divide 3657 by 10 and if you if you want quotient so quotient will be 365. Now 365 modulus 10 so B will be having 5. Okay and if you divide number by 10 so 365 by 10 will be 65 sorry will be 36 and that I will be storing into num again. So here num will be having value as 36. Now I need to write one more step C equals to num modulus 10 right and D equals to num divided by 10 so till here at line number 12 num is 36. So what I need to do 36 modulus 10 so here C will be here C will be 6 and if we come to next line. So here D will be 3 here D will be 3 so you can see 3657 all 4 digits are now in separate variables. So Rajiv you pasted your answer so just verify it with my answer like whether it is same or not if it is same so you are good. So now what I need to do I just need to add all these A plus B plus C plus D so this way all 4 digits will be added and there some will be displayed. So it's some will be 7 5 12 6 18 3 21 so it's some will be 21 so this way if you have 4 digit number so with the help of 10 only you will be able to have the result. I know steps are increased but later on what we'll be doing we will be implementing a loop loop means repetition. So if you have a repetition in any logic so you can reduce that with the help of loop and loop will be repeating those statements automatically. Okay so I hope this way you are able to understand this now let's check what will be the output so I'm just clicking on run. So here you can see result is 21 which we expected. So it means code is working fine code is working fine now we have next problem which is read a 4 digit number and we need to print reverse of it. So can anyone tell me what I need to modify in this code so that I can have reverse of 3657 or any other 4 digit number that I provide into num. So what I need to modify here so it will be a quick solution. So if you can write that solution in the chat so that will be good and I'm liking today's session like lots of folks are interacting and participating. So soon I know this bootcamp also will be having lots of folks because in India like BTEC admissions are going on and maybe in July or August they will be having their classes. So if you know anyone who just passed their 12th and want to enter into BTEC and they want to learn their first programming as C or C++ so just share this bootcamp information with them so that they can also start their programming journey. Right so we have socket solution so A into 1000 B into 100 C into 10 and D yeah. So let's see so I am multiplying it by 1000 B I'm multiplying with 100 C I'm multiplying with 10 and I'm just clicking on run button. So we have 3657 so let's see what will be the result yeah so it is having 7563 so socket your answer is correct. So this way if we modify this printf statement so automatically the four digit number that we have its rewards will be available. Yes Mahima your answer is also correct. Okay so this way like all four programs we are able to understand so this is it for today what I prepared for you and from next week Monday onwards we'll be having new topic that is conditional statement. So if you have any doubt in this logic so you can ask in the chat otherwise we'll be meeting on Monday with new topic and new problems. And don't miss next week onwards sessions because those will be difficult so till now we have covered the basics of C programming from next week onwards we'll be covering the advanced topics. Right and I will be modifying the session tracker so I will put some pre-recorded videos as well so that you can use those for your reference purpose. Okay so this is it from my site for today thank you so much for joining today's session and being participate in the session so thank you so much see you on Monday with some new problems. Thank you take care happy weekend bye bye.