 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. You are watching SEALanguage video series in Hindi and it is for beginners. In the last video, we saw how to use loop. I got familiar with one loop which was for loop. I told you how to implement these programs. In this video, which is lecture number 11, we will know more about for loop. In this video, I will tell you more programs which are listed in front of you. Let's start with the first topic which is loop in decreasing order. If you watch the previous video carefully, you can see the slide which I told you. In that, we printed natural number, even order, table print and series print. I told you about loop in increasing order. Now, we will see how to run loop in decreasing order. If you want to take online classes or connect with me, you can discuss any problem or any doubt. Normally, when you watch video content, you understand many things but some doubts remain in your mind. Many video tutorials do not provide you with the facilities to clear doubts. I am sharing my information through which you can connect with me and clear your doubts. Let's start this video. I will tell you how to run loop in decreasing order. First, let's include header file. I am declaring a variable. Then, let's create a number with the value of n. Let's scan it. If I want to print the natural number, I will start the loop from 1 to n and run it in increasing order. But my requirement is to print the natural number in decreasing order. For example, the user has inputted 20. In increasing order, we will print 1, 2, 3, 4, 5 up to 20. But we have to print it in decreasing order in 2019-18 up to 1. For that, we will initialize the for loop from n. I have written i equals to n. The condition will be i greater than equals to 1 and i minus minus. This is the initialization of the loop from n. The same value is available in n. It will be assigned in i. Till the time i is greater than 1 and equals to 1, the loop will repeat. And i will always decrease from 1. For loop, we have to repeat printf. I have written backslash n, percent d and i. You can implement this loop in decreasing order whenever you have a requirement. I have saved it. After saving, we execute it. I have used extra slash here. I forgot to declare n. Whatever variable you use, it is necessary to declare it. You have understood this if you have seen all the videos. I have inputted 10. You can see that the natural number is printed in decreasing order. Friends, if you want to run any loop in decreasing order, that is also possible. Now we have to print the sum of natural numbers. If you see the previous video, I have told you to print as many series as possible. Now we will perform a calculation. The final result of the calculation will be printed on the screen. In the previous programs, you must have seen that the printf is repeated with the loop. But this is the first program where the printf will not be repeated with the loop. The loop will only repeat the calculation. And after completion of the loop, the printf will only be executed once. So calculate the sum of natural numbers. So this part will remain the same. There is no need to change it. You will have to declare only one variable. S, which will store the sum. Now I will start the for loop once. Or you can run it in increasing order or decreasing order. There will be no difference. So we will run it in decreasing order first. Then I will convert it in increasing order. Now I have put the curly basis so that you can know that the statement repeated with the loop is in the curly basis. And the statement written after closing the curly basis will not be part of the loop. And if there is only one statement, then we can remove the curly basis. So I am writing s equals to s plus i. And after closing the loop, I will print the sum. So I have written sum equals to percent ds. So now let's iterate it and see how it will run. So we will declare the variables below. We will set the value of the variable. So let's suppose the user has entered n. And s is initially zero. So when we will start the loop, then this statement will be the first one. i equals to n. So what will be the i? 5. Now check the condition. So 5 is bigger than 1. Condition is true. So now this statement will be solved. So what is the value of s? 0. How much is i? 5. So 0 plus 5 is added. And who will get this value? s. So what is the new value of s? 5. Then we will go to i minus minus. So what will be the i? 4. So i is decreased. I will check the condition. Condition is true again. Now we have to solve s plus i again. So you saw that now this calculation is repeated. Nothing is being printed. Now we have to repeat the calculation. When will the print be terminated? So what is the latest value of s? 5. And what is the value of i? 4. So what is the value of 5 plus 4? 9. So in s, you will get 9. So you saw that 5 and 4 are added in s. Now again i will decrease. i will get 3. So here it will get 3. Again add s and i. And before that the condition will be checked. 9 is 3. So 9 plus 3 is 12. So in this way these values are being added here. And when this loop will be completed. Means when the value of i will be zero. So the loop will be completed. And after that printf will only be executed once. Which will display the sum. So now you can understand that whenever you print through the series through the loop. So printf will be repeated with the loop. And when the loop is completed. After that you have to display the result of some calculation only once. So after closing the loop. You have to display the value of that variable through printf. Okay. So i hope you have understood the difference. Now let's see it by executing it once. So i am entering 5. So as you are watching this video. So you have to calculate it. 5, 4, 3, 2, 1 or 1, 2, 3, 4, 5. If you add it like this. Then the result will be 15. So i have taken a small number. So that you can easily calculate it. To justify the program size or not. So 1, 2, 3, 4, 5 will be added. So it will be 15. So the loop was going in decreasing order. So the result is 15. Now it is going in increasing order. So i will start from 1. Condition will be i less than equals to n. And i minus minus is i plus plus. Everything else will remain the same. Again let's execute it by saving it. Let's enter 5. So you will see that it is still printing 15. So in this way you have seen that the loop we are implementing here. It can be run in increasing order. It can be run in decreasing order. So it will depend on your requirement. Okay. So i hope you have understood how we can repeat the calculation through loop. Let's move on. So next is calculate factorial of a number. So calculate factorial of a number. So if we talk about factorial. Suppose number is 5. So we have to calculate the factorial of 5. So it will be calculated in this way. Mathematically if you want to start from 1, 2, 3, 4, 5. Means we have to start from 1. And the number is 5. So multiply all the digits from 1 to 5. The result of that is factorial. So we can run it in increasing order. We can write this also. Both are the same. Results are the same. So what we will do is we have added 1, 2, 3, 4, 5. Now we will multiply it by simple. Your factorial will be calculated. So you have to keep in mind two things. Whenever we will multiply. Whenever we will multiply. So the variable will be zero. Because if you multiply it by zero. So the result will be zero. And after the loop is over. You have to change the message print. So you can write factorial equals to percent s. If you want to write the name of the variable if you want to write the effect. If you want to write the significance. So that is also possible. So let's say I have written the effect. So what I have written instead of s. So if you change the variable. If you do it above. So you have to change the subject. So see how easily we have converted the sum of the natural numbers. To the factorial calculation. Because there we have to sum all the digits from 1 to n. Here we have to multiply all the digits. So let's run this again. If I enter 5. So 5 factorial is 120. So if we multiply 1, 2, 3, 4, 5. Then the result will be 120. So if you enter any number. Then the factorial will calculate you. And the result will be displayed. So after calculating here. Finally we have to print one result. So we have to loop print f and take it out. Now if we have to avoid the curly base. Then it is possible. Because the for loop is repeating the same statement. So you can write it like this. So now for automatically. Only the calculation will repeat it. And the print f will not repeat with the for loop. So you can avoid the curly bases. If you want to repeat with the same statement loop. There are more than one. Or you are confused. That I don't want to use the curly bases. So that I know which statement is repeating. So you can use the curly bases. So I hope you have understood till here. Now we will modify this program for the next calculation. So the next is Calculate Power. So if you pay attention. So I told you in my video number 6. That how we use P and W pre-defined functions. So those who have not seen this video. So those who are watching this video. If you go to the description of that video. So on the first number. You will get the link of this video series. So there you can see this video number 6. So in that we have used P and W pre-defined. Now we will write our own code to calculate the power. Where we will not use the header file. We will calculate the power through the loop. So whoever wants to follow this series. So I am telling you again. In the description of every video. In this video series playlist link. And whatever other video playlist links I have made. Or video series I have made. You will get all the links. So you can follow them. They have been made in English. And they are in Hindi. So I have made a lot of videos. So they will be helpful for your learning. So Calculate Power. So you have to calculate the power. So in the front bracket. 1 number raised to the power of another. So normally when we calculate the power. So we write 2 raised to 3. Or 5 raised to 15. Means 1 base number and 1 power number. So now we will declare one variable. P will declare one variable. And 1 will declare the result. And we have initialized it from 1. Because here also we have to do multiplication. Then I have written enter base and power value. Because there will be 2 inputs. We should know the base and power. So there are 2 inputs. So I have written 2% and modified the scanup. Now let us understand the logic of this. If the user has input base 2 and power 3. So how do we normally solve 2 into 2 into 2? If we multiply 2 3 times. Then the result will be in front of you. If this was 2 and power was 4. Then how many times do we have to multiply 2? 4 times. So we have to multiply it. B means base. And how many times do we have to do? P times. Means the value of P power. We have to multiply B. So from this we know how many times we will repeat the loop. P times. So I will start from 1 and P will iterate. So if P is 3 then loop is 3 times. If P is 4 then loop will be 4 times. So power value will repeat the loop. And we have to multiply B. In this program in multiplication I will not be used. I will only control the loop. So we will write RS equals to RS into P. Because we have to do multiplication of B. And we have to store the result in RS variable. So we will iterate this loop for once. And before that I will write result equals to %d RS. And this printf will not repeat with the loop. Only once. So the loop is not the same. So let's run it. So let's take a small number. P is 3 and B is 2. I started from 1 and RS is 1. This is our value. So we will start the loop and check if it is smaller than P. So P is 3. So I is less than equals to P. Condition is true. Then multiply the result from B. So the result is 1. So 2 into 1 is 2. So the result is variable. So the value of the result is 2. Means the base is multiplied once. Then I is plus plus. Then I is 2. Then again check the condition. 2 is smaller than P. Yes. Condition is true. So RS will be multiplied from B. So this statement will be solved. So the value of the result is 2. And B is 2. So 2 into 2 is 4. So the value of the result is 4. Then I is plus plus. Then I is 3. So I is 3 and P is 3. Means this condition will be true. Again this calculation will be solved. So the result is 4. So the base is 2. So the value of the result is 8. Again I is plus plus. Then I will be 4. Now check the condition. 4 less than equals to P. So 4 less than equals to P. No. Condition falls. Means this loop is terminated. Now we will come to printf. So what will printf do? RS will print the current value. And current value is 8. So the power of 2 is 3. So this way we calculate the power through loop. So you must have understood the whole process. So now let's erase it. Save it. Now let's run the compiler. So I gave base 2 and power 3. So you can see the result is in front of you. 8. Ok. If we run it again. And input 2 and 4. So the answer will be 16. Because the result will be multiplied by 2. So 8 into 2 will be 16. So this way friends we calculated the power. So I hope you have understood this. So you saw that we are calculating in every program. And after the loop is over, we print the result. So I hope you have understood this. So after the loop is over, we print the result. So that's why we learnt to print series in the previous video. And in this video we will repeat the calculations. Now we have 2 more programs left. One is the prime number. We have taken any number as prime or not. And then we will print a series. Ok. So first let's check the prime number. User will input a number. And we have to check if the number is prime or not. This is very interesting. And in this you will get to see a lot of new things. So let's erase this. Ok. Now I will also do the implementation. And along with that we will discuss the logic as in every program. And I hope that you will enjoy these video series. Because I will also give you theoretical explanation. You are also seeing practical implementation. So it is not that there is any problem in my writing. Because you are typing directly. And I will also explain the things. If you have any doubt or you have commented without hesitation. Or if you have shared my contact details in the beginning. You can directly connect with me. That we don't understand this. If you can understand this by taking 5 minutes time. So I will be available. Ok. So let's start. So to calculate the prime number. We will run a loop. So I variable. User will input a number. And variable. Ok. Then I have written printf. If you will read the extra variable requirement. So as soon as we will use it. Then we will declare it here. Enter value of n. You can also write enter the number. Who is you want to check. Whether it is prime or not. So printf message you can customize according to your according. This is the number in your pass. Ok. Some of you must be thinking that what is prime number. First tell me how to check. Because in mathematics you read but it may not be there. Ok. So we will discuss it. So we took a number 7. And took a number 6. Ok. So to check any number whether it is prime or not. So what you will see. Whether that number is divisible from one or self. So every number is divisible from one or self. Ok. Now if any number is divisible from one or self. Then only that is prime number otherwise not. So you will say who is the prime of 7 or 6. So you check. Whom can we divide from 7. From one and from 7. 7 cannot be divided from any other digit. So 7 is prime. 6 is divided from 1, 2, 3 and so on. So 6 is not prime. So in this way you have to identify whether the number is prime or not. Now we have come to know that every number is divisible from one or self. So we have to ignore them. We have to divide from them. Apart from that the number of digits is 25. So 25 is divisible from one or 25. So what we have to do. We have to check the digits from 2 to 24. Whether they can be divided from 25. So they can be divided. So it is not prime otherwise it is prime. So now you might have an idea of where to start the loop. From 2 to where to start. Less than n or less than equals to n minus 1. It is the same thing and i plus plus. You might have understood why we started from loop 2. Because we have to divide from 1 to any number. And where to start the loop. From n to less. i less than n equals to n. If you put equals to n then you have to write n minus 1. So it is the same thing. Now I will tell you one more thing. If the number is 25. So 25 can be divided from the numbers of half. So 25 is 12.5. So if we take 12. So the digits from 1 to 12 can be divided from that number. The bigger number can never be divided from that number. So shall we half the loop like this? Or put equals to n. i less than equals to n by 2. So let's suppose number is 50. So divide 50 to 25 from 2 to 25. Because the digits after 25 will never be able to divide 50. So that is why we have reduced the rotation of the loop. So I hope you have understood this. Now let's talk about the division. Now let's take the number for example 7. So we have to divide 7 from these digits. Who will always divide n? So let's see the program. If n. We have to divide n always. Now whether it is being divided or not completely. So for that we have to check the remainder. And what do we use for the remainder? Modulus. And to whom do we have to divide from i? And whether it is being divided or not. Who will tell that if the remainder is equal to 0. Then it is divided. If it is not equal to 0. Then it is not divided. So n will always be fixed. Because if you look at this loop carefully. So we have not modified n anywhere in the loop. Who are we modifying every time? i. i was always 2. Then it will be 3. Then it will be 4. This is how we keep on increasing. Okay. And if this number is divided from i. Then the result will be equal to 0. Otherwise not. So now you must be thinking that we will write this. Print f. If it is equal to 0. So not prime. And else we will write prime. Okay. This is its one approach. If the number is divided from i. Then it means it will not be prime. Because we are running from loop 2. And we are running from n by 2. Means the number is not being checked by itself. Other than that it is being checked by digits. So if it is divided. Then it will not be prime. Otherwise it will be prime. So let us check for once. Will this approach work? So we take number 9. Okay. And 9 will be divided. So we take 9 by 4. Means the loop will work so many times. 2, 3, 4. Then see. 9 will be divided by 2. So will 9 be completely divided by 2? You will say no. Reminder 0 will not come. So what we print is prime. So when the loop is increased and it is checked by 3. Then it is divided. So what we print is not prime. So this logic is incorrect. Means we cannot print this in the loop. Whether the number is prime or not. Because it is not necessary that it is divided from the first digit or not. You can decide based on whether it is prime or not. There are some numbers that are divided from the third digit apart from the second digit. Okay. So you have to identify whether the number is divided or not in the loop. Okay. So remove this printf. And remove the else too. Okay. Now I am using another variable here. Flag. Which is initially 0. As soon as this condition is true, then flag will be 1. Okay. Which will tell you whether the number is divided or not. So initially flag was 0. Number is 9. So we first divided 9 from 2. So will 9 be divided from 2? You will say no. So will this condition be true? No. Because the remainder is not 0. So there will be no sign in the flag. Then there will be no more. Then there is I++. Okay. How much is I? 3. So whose number will be divided from 3? So will 9 be divided from 3? You will say yes. So what is the sign in the flag? 1. So when is the sign of 1 in the flag? When the number will be divided completely from a digit. Okay. It means after the loop is over, you will just check the flag. if there is flag 1 you can print a not prime if there is flag 1 it means you will print a not prime because it has been divided and if flag remains 0 you can print the prime now you will say it remains a 0 if there is number 7 it is equal to half of 7 so we will divide it with number 2 or 3 then is the condition also correct in 7 case? so there is no sign in the flag, if it is not true then there is no sign in the flag so what was the beginning value of the flag 0 when the flag started from 0 to 0 and there is no condition अदो लुर्ब क lange Krishna will happen? लुर्ब करते हैं। अदको ज Тем more given, अदको अब नहीं Mad देवैद � reign के कुझा क़ तो बत तको रहारे.. या फिख ठराला자 होसी फ्लार तो णब मun कि तो eliminator of 5..its value is only 2 ौ 12 तीसे आप स --> अप कहुए णब कहुए ढ़uta ौवो आप आप आप आप आप आप आप आप आप, but if a value of an variable 한 सेड aşk Rena Аब आप सשים तो खना आ ہیں का कि रवाग कहञ। लगकजो  transporting from 5. After condition at 59, तो आप ज़ॉब थी एक आप प्रोसे से गई था आप ड़ॉप को आप चाही जब रोग दे अप आप आप आप बद़़त नहीं तो उसको स्थोप कर दो जो अणषर यस तो जैसे यह यह भी उप्कन्टिशन तू जाएगा, it means number किसिना किसि जिज़ेट से दभाएद होचुकाएँ, and flag value of 1 set on the side, तो हमें लूप को और अगे नहीं रोतेट करनाएँ, so hamein ab loop ko aur agin nahin rotation karnaay. तो आप क्या करेंगे एक क्यी वर द्योंगे ब्रेक, तो ब्रेक क्या करता है, टरमिनेट्स एकसिकुषन अप लूप, तो ब्रेक आप आप और दे लिए लिए ऱ कर चुकें अंडर. जर मैं आप को स्विच पडाया था, तब भी मैं लेग तो ना बताया �the कि जब आप एक स तो इस तरीके से अगर अप इसको भी रन करेंगें तो ये प्रोपर ये एज़िकूट होगा तो अगर मैंने नमबर डला 25 तो ये प्रिंट कल देगा नोट प्राईं और जैसी 5 से देवायद वा, तो उसी ताईंपे लुप स्तोपचाए तो इस तरीके से आब आपको समज्मे आग्वावावे कि हम कैसे चेक करेंकें कि नमबर प्राइंई है आनी अप मैं ब्रेग का यूज़ भी आप को समजाद या एप और ब्रेग का यूज़ मैं आप को लास में भताने वलाग आप ब्रेग एं करतीएोगी वर तो एक चोटा से इजाम्पल लेंगे, जिस में इसको फिर्से रिवाइस करेंग, उस से बहले दिखते है, फिर्भूना के सीरीज कैसे प्रिंट होती. तो तो करते है, फिरेज. और प्राईम नमवर इजाम्पल लेंगे लेंगे लेंगे लेंगे प्रिंट करना है, फिर्भूना के सीरीज. और मैं बारभर बोल रहा हो, कोई भी दाउत हो, मुस्ते कनेख करेंग, ता की आपको जोगी प्रोबलम्स है, उसका सोलेशन में लेंगे, और आप कंफुज ना हो. इंगे यहापन यह तीटिवी डीवोग लाई. तीतम तीवन तम वन यह जोगे और अबगी ही धनिगली लुब करसी अगि शाझ्ट कर रहा है, अप चात fazla अच tail अब ही बध्त्ते कोन combinations like t equals to t1 plus t2 than t1 equals to t2 and t2 equals to t term 1, term 2 add occur in t and then term 2 assign to term 1 and term assign to term 2 and this loop will continue because this is a series you can see the printf loop has come third rotation, i++ । । । । । । । । now again print । । । । । then what will print । । । । print । । । । okay now add t1 and t2 then how much will be in t1 and t2 so how much will go in t2 so I will assign term 1 to term 2 so term 1 will be 2 assign term 2 to term 2 so this will be 3 fourth rotation complete then i++ will be 5 again to print । । । । । अमने 8 आँब नया वहार का उरीव जा़ता हैंग़े कुई जा़ता हैं तो दियो ग़ोंग़े फार पूँर बाश्टी करते। तो तो उसको प्रेंट कराब है। तो मैं या एक प्रेंट तेफ और उस कर जाूं चीके और ब्रेएख सर्फ के साथ रपीट होगा कि मैंने करली बेसस नहीं लगा है तो इप के साथ अर्टमेंटेग लिए एकी लाईन रपीट होगा उसको उसको थीखे प्सब देखा। तो उसको लूगे नहीं व़ा रपीट हो ग़ोगा और अगर ख़ा कन्टिनॉँ यूस करता होगा थो ख़गा अगर लोगा एक रोटेछन करेगा अखलाब जब i3 है, तो continue इस प्रिंटेप को श्किप कर देगा और control का चले जाएगा i++ प्रिंटेप कर तो 3 के अलावा सब कुछ प्रिंट हो जाएगा देखो 1, 2, 4, 5. तो break तो loop को stop कर देगा, जब की continue एक rotation श्किप कर देगा ताम्ता और ये दोनो कीवर्ट्स होते है, तो जब भी आप को रेक्वावेंट हो आप पने को लुज कर सकते हैं तो इस तरी के से ये वीटियो अप कमप्लिट होगा, मैंने आप को इतने सारे प्रोग्राम्स का देमूंटेशन दिया की कैसें को प्रिंट करते हैं और अगले वीटीो के انले अप दिखेंगे की में आप को बतावन्वाश वाई लुग कैसे लिएंट होते है। उस वीटीो में भी वी सें चवमट में दिसकष्शन करेंगे प्ले संटेख्स तो उज़ेँ सीद करतेंगे जागा एक लोगिए तो नहीं थाए आप वीडियो सीदी जाए कता है, और जो बी आप के सजचन से दफॉट्से है, वो से दिसकस करो बगए दीटेल साप के पास अपलिब लिए आप आप यो वेडियो सीदीजे एस को एनजोय कर रहे है और जो �