 Hello friends, I am Sanjay Gupta. I welcome you again on Sanjay Gupta Tech School. So this is lecture number 5 and in this lecture we will discuss some programs related to this language. So the objective of the programs is listed in front of you. So let's start with the first program. So the first program is Sum of two digit number. So first let's understand what we actually have to do in this program. Then I will tell you the solution step by step. So let's go to the C compiler. So it is dev C++ where we implement all our programs. So basically what we have to do is sum of two digit number. So sum of two digit number. So let's read this in more detail. So for example you have this number at 24. So what you have to do is you have to do this. 2 plus 4 and you have to show the result at 6. So basically what we have to do is we have to separate the number of two digit number. Like this example at 24. So we have to store two in a different variable. Four in a different variable. And then we have to sum them up so that we can remove the sum of two digits. And always remember that in the objective of the program, there should be two digit number. So the input should always be two digit number. So let's start from the beginning of the program. First we have to include the header file. Then the main function. We have declared a variable in the main function. And now the second variable is D1 digit 1, D2 digit 2 and sum. Then I have written printf. Now the message in printf should be clear. So now we will write enter a two digit number. So we have to input one number. But there should be two digits available in it. Right. Scanf, %d, %n. So now in the n variable that number has come. Where there should be two digits. And we have to add the two digits individually. Okay. So now look at it in a little more detail. So I will open the print for once. So now we have taken an example, 24. So let's say this is our number, 24. Okay. Now let's divide it. So to divide, I am taking digit 10. Okay. So if I divide 24 from 10, then it will be divided twice. And the result will be 20. And what will be its remainder? 4. Right. So if we divide any number from 10, then the first digit of it, so keep in mind that number is only 2 digits. So for 2 digits, if we divide the number from 10, then the quotient of it will be the first digit. And the remainder of it will be the second digit. Okay. Now I have already told you in the operator lecture, that if we want to take out modulus, then we use percent symbol or if we want to take out remainder, then we use percent symbol. And if we want to take out quotient, then we use divide symbol. So if you want to take out 2 as a quotient, then you use divide symbol. And if you want to take out 4 as a remainder, then you use percent symbol. So how will you implement it? You will write d1 equals to n divided by 10. So divide will be provided by quotient. So if the number is 24, then what will be in d1? 2. Okay. Then we have taken d2 equals to n, modulus 10. So this is the remainder. So if we divide 24 from 10, then what will be remaining? 4. So here in this variable, what will be d2? 4. Okay. Now we have to calculate sum. So you will write sum equals to d1 plus d2. And after that, we have to show it on screen. sum of digits equals to percent d sum. So printf, we have already discussed in detail in previous lecture. So if you want to revise old videos or if you want to see old videos, in the description of this video, you will find a playlist link in which I have arranged all the videos related to this series. So you can see all these videos in that playlist. So those who have skipped the operator data type videos, you can also see those videos there. So divide will give you quotient in d1, modulus and percent symbol will give you the remainder which will come in d2. So I will input 24 and in front of you you will see sum will come in 6. So first let's save it in the name of test.c Now let's compile and run it. So I have entered 24. So you can see sum of digits equals to 6. Okay. Now if you have any other number input, then let's say I have entered 81. So result will come in 9. Okay. If we enter any number result if we enter any number result will come in 9. So result will come in 9. So in every case it is working properly. So why it is like this? Because we have separated the first and last digit from the divide and modulus. And if we add them then sum of digits is in front of you. Okay. Now let's see one more example which is the second example. So what we have to do in the second program is reverse of two digit number. So we have to modify it a little bit. Now we have 2 digit number at 24. So what should be the output? 42. Because what will be the reverse of 24? 42. So now let's modify this program. So this is saying reverse of 2 digit number. So again here the input will come in 2 digit number. And you have to reverse 2 digit number and print it. Now let's see what we have to do to reverse it. To reverse it we have to do 2 and 4 separately. Here we have to say first and last digit separately. So it means till here the code will remain the same. Till line number 9 you don't have to change anything. Okay. Now let me give you a situation that you have 2 in D1 variable and 4 in D2 variable and we have to print 42. We have to print 42. So this means how we will solve it mathematically. So what logic will you get? You multiply 4 by 10. So it will be 40. And add 2 in it. So what it will become? 42. So now see what is 4 in D2? So what we will do? Here we change the name of the variable. Reverse. Because the variable should always be significant. Now I have told you that we have to multiply 4 by 10. And 4 is our last digit which will come in D2. So we will write D2 into 10. And in that we will add D1. So now it will print reverse. So you might have understood that I have multiplied the second digit D2 from 10 and added the first digit in it. So the rest of the logic is the same that how we will do it separately. And this logic will help you in the upcoming programs. So always keep in mind that whenever we use divide or modulus operator then divide portion provides and modulus limiter provides. So now we save it again. We run the compiler. So I am entering 24 again. So you will see that the result will come. So in this way if you enter any 2 digit number then you will get the reverse. So always keep in mind that 2 digit number is the input. Now you will say that 3 digit, 4 digit what to do. So for that you will have to make a separate program. Then you will say that for every 2, 3, 4, 5 different number of digits you will have to make a different program. So this is not the case. In the upcoming videos you will read a topic called loop. So loop means repetition. So with the help of loop we will make a program that will lead to any digit number you will get the reverse or sum of digits. So for that you will have to be patient. In the upcoming videos you will get to see that. So for you there is an assignment that you should apply this 2 digit calculation on 3 digit. And if you have any doubt then my details are available here. You can communicate with me or you can mention in the comment section then I will help you in the logic. So this is the sum of digits sum and reverse. Now let's move on to the next problem. So the next problem is that we have to convert the hours, minutes and seconds into total seconds. So let's say you have time. For example you have 1 hour 30 minutes 50 seconds. And you want me to make total seconds of 1 hour 30 minutes 50 seconds. Means I have to convert the hours minutes into seconds. And the seconds are already seconds. So hours, minutes and seconds when they convert then if we add them all then we have total seconds available. So if we try to implement this program then you should first mention it in the comment section. Read hours seconds convert total seconds then see here we have to identify what is the input. So in this program you have to do total 3 inputs. First is hours, second is minutes and third is seconds. Then we will convert the hours minutes and the converted values of the hours, minutes and seconds then we will get total seconds. So I will give you the variable r minute second and total seconds. For a printf then write hours minutes and seconds. Now we have to input 3 numbers and 3 are integer type. So as I have taught you in the last video that if there is one number then only 1% is integer if there is float then %f is used but here in integer type there are 3 numbers. So how many times we have to write 3 times %h %m %s So in h we will get hours minutes and seconds So this is very simple Now your math comes. So if you think mathematically we have to convert the hours in seconds so how many seconds in 1 hour 3600 then multiply the hours 3600 If there is 60 seconds in 1 minute then multiply the minutes 60 and the seconds are already converted so we will use it as it is. So I write total second equals to hours into 3600 So this is our equation. See we will close it here So this is how we convert the hours in seconds then we have to convert the minutes then we have to convert the minutes in seconds So how many minutes we have to multiply the minutes from 60 and the seconds we have to design So hours into 3600 plus m into 60 plus s So if you have this problem in maths then you apply this formula So in programming we are doing mathematical implementation so that we don't have to write one program again and again and we can run it and we can receive it So this is the benefit of programming So now we will have total seconds in TS variable so we have to print them Now I have written total seconds equals to hours into NTS Now remember that if your range exceeds if you have any wrong output then you have to keep in mind that integer variable 2 bytes only stores if you have any wrong input then you have to use long int so take care of that and this size also varies from compiler to compiler so in case if garbage value comes in your mind then you have to keep in mind that the range doesn't exceed So now I have implemented now what we will do 1 hour, 1 minute, 1 second So I save it execute it 1 hour, 1 minute and 1 second So how many seconds in 1 hour 3600 How many seconds in 1 minute 60 and 1 second already So 3600 3600 plus 60 plus 1 So this will be 3661 this is in front of you So in this way I have inputted hours, minutes and seconds separately by applying formula I have converted all of them in total seconds So this was a very simple example and now I am telling you this simple example so that you become familiar with the programming So now our lecture number 5 is going on when we will continue to study so I will give you more examples so that you become comfortable with the programming So till now we have covered the introduction in the first and second lecture In the third lecture I told you the data type In the fourth lecture I told you the operators In the third lecture we discussed the data type In the fourth lecture we discussed the operators In the fifth lecture I will tell you some programs So if you want to discuss more basic programs then I have already told you the details You can mention these things in the comment section So I will try to understand you in the simplest way I will deliver you So if you have any doubt that you want to discuss what the trainer is teaching then you can I will be available for you so you can discuss it Because sometimes after discussion you get clear quickly And whenever you implement these programs you will always think that we are solving mathematical problems through programming And also keep in mind that if you practice daily then you can be familiar with any of the programs Then next is swap two variables using third variable and without using third variable So in this one program there are two concepts So we will divide them First we will swap using third variable then we will convert it without using third variable So let's erase this Let's change the heading of the program Let's change the heading So we have to make three variables ABC So if you want to input 2 values then you have to scan these numbers so you can scan these numbers because there are 2 numbers So 2x %d %a, %m Now you may be thinking that it's not a big deal that you don't know the meaning of the word So swap means to interchange आपी आपन मान के चलत हैं और अजूम काना होCONFIRMATE of 5, A in 5 & B in b. ये अजूम कर ल Investment on run. इसे अप रहंे के अप वल्ग लेग हैं. volte When i'll run this program, input and print F to a value or a and b have to interchange the values, instead of SECOND, A and TEN should be printed And BT should be printed So its a two way of sweet연 and we have to solve it upstairs with 3rd variable ज़ाप दिखगो, अगर हम अदेरिखलिय मसोल करने वोजक्छ करने आच्गरी के फिले, मैने लिखा एएईक्फेलक तो बी, एच्डा मतलब क्या है, फ नहीं, अंप में एक आप आपरडर दे उस करने एग सिझी, इसने सारक्वाभ구요, तो जोकी रीटहें सआएट की ज़ेल जो जीवापु च् tens, परिक रेको आप पक dude's. यो ठेण՛ वेरते है भ सफाँ से न now we are making a block as C थी क categorically this is going थी कि कि kematics ऽहती लेके जी प् Bro ke card को अदन वर्ँफान के लूहते इसका मतलव, right hand side, variable की वाई लेपन्टिन सटब पहशायंग़ाईग़ी, तो right hand side पर कोनध? a. a अपनी वाईउ किस तो देगा c को, तो a की वाईईउ क्या आब? 5. तो c के पास बी क्या जायाईगा? 5. तो इसी लिए इंको बोलगाता है, विडिये बड़, ये ताएम तो ताएम अपनी वेलू चेंच कर सकते हैं, तो एमे पहले ता प्फ, और अबी कितना है, तैं, तीक, तो यही हमें करना ता, तो इसको रन करते हैं, मैंपुट में 5, 4, 10 लेता हैं, A5, B10, और अब देक सकते हैं, के A10 प्रिंट करता हैं, और B5 प्रिंट करता हैं, तो इस तरीके से यह पन ने सुल किया, स्वाप्टिंग, अफ तु वेल्यबल्स, यूजिं तर्द वेल्यबल, अब हम इसके आगे आड़गतेता हैं, बिडफुट यूजिं तर्द वेल्यबल, तो किसका मतलब अब जो डायग्राम होगा वस में C की कोई जरवत लिए, अब C की कोई जरवत नहीं हैं, तो हमें कोड भी चेंच करना बड़ेगा, तो C को यहाँ से हतादेते हैं, यह तीनुनाई नहीं हतादेते हैं, बाकी आज़े तुस रहेगा बस लोजिक चेंच करते हैं, तो देखो, तीन statement लिखें हैं, पहला मैंने लिखा A equals to A plus B. तीक, फिर से समजने के लिए दोनो लोकेशिन तर्व कर लिए देखें, तो यह है A, value of 5, गूँसी लोकेशिन बनाराव भी, अर बी की वेलिव हैं, 10. तीक आप मैंने जो स्टेट में लिए लिए लिए लिए लिए लिए लिए लिए प्वल्स बी, तो पहले रही दिंच सैट को सोल परोग. A plus B, तो A में कितना हैं? 5, B में कितना हैं? 10, यह लेए लिए वोगावे कुझो अर बी हो सकती हैं, ताब कुच से टिवालिए ताब षोग लिएBA. अर ओवग देख़े मगदaper यहोर भीको यहात है और थे आदित वल्यों थी वहाम आई में आई में आसाईईगी. चीख तो आई में गरन्द में टेक पस फीझती चे अग वे कभीखे पस क्या एण? छीख अब मैं लिक रहा होँ, क्यों वे एण में वेशाँ बी. इसको साल करते है. तो आप देखो यहान लिखा है A-B तो A के पास करन्त्ट्टी कितना है, 15, और B के पास कितना है, 10, तो 15-10 कितना है, 5. और हम असाँिन किस में कर रहा है अस्फो, B के अंड़, तो 5 किस के पास जाहेंगा, B के पास, तो यहान के आ आगया. तब दिखो A-B मतलब 15-5 दिखरेंस आया 10 और वो किस में साईनो जाएगा A के अंदर क्योंगे हम ने एक इखवल्स तुके लेप्रेंट शाइत पर क्या लिखावा A लेप्टोप या टेक्स्टोप पर रन कर के भी लिख सकते हैं और कोई भी दाूत हो, तो मेरी अन्फरमेशन आप के पास है, आप खमेंट कर सकते हो, और आप जाजसी आदा एं वीडियोंस को देख हैं, रही वो ब्ली अब ब्ली टेख है, प्ली लिएज़ी भीडियो भी लिएज़ी ने अभी नवेलेप लेपटोप आप बी देख हो, और अपने फ्रैंट्स को भी शेएर कर उगर हैं,