 Hello friends. I am Sanjay Phukta. I welcome you on Sanjay Phukta Tech School. In this video, I am going to explain a program which will be calculating power value. So here we will be having two digits. One is base and second will be power and we need to calculate this. So 2 raise 3 equals to whatever will be the result that we need to calculate. So before starting, if you go to detail or description of this video, so you will find links of various players related to programming. So you can watch them too. So now beginning with this logic. So here you can see we need to calculate 2 raise 3. It means we need to perform this operation. 2 will be multiplied 3 times so that this calculation result can be implemented. So if we have a base as 2 and power is 3, so we can do this with this method like we can multiply 2 3 times, but let's say if it is 30. So is it possible to multiply 2 30 times like this? No, we cannot write 2 into 2 into 2 30 times. That will be not a good practice. So to simplify this problem, I am going to implement this solution with the help of for loop so that this multiplication can be done automatically. Whatever will be the value of R, right? So based on power, this base will be multiplied so that we can identify the result. So let's say right now power is 3 and base is 2. So I'm writing it from the beginning. So I am taking the variables base, power and result. So it is initialized with one. So it's initial values one that I'm going to use. Then inside printf, I'm writing enter base and power. Then scanf for sending 2 times because we are building 2 values. So base will be stored inside b variable and power will be stored inside p variable, right? And also remember that we are not going to use predefined functions. So there is a predefined function that you can use like this and this is used with math.h hydrifying. So we are not going to use this. I'm going to tell you how this predefined work can be done with the help of loop. So that is important to know because in many examinations that can be asked like without using any predefined function, implement this logic. So that will be better to know. So now if we implement the logic, so here you can see we every time are multiplying base value, we every time multiplying base value, right? And how many times you are multiplying? It depends upon the part, right? So it is clear multiplication will be done for this and how many times will be dependent upon the part. So if I want to multiply to 3 times, it means loop will repeat 3 times. So here I'm going to write i equals to 1 and rotation of this i loop will depend upon this p. And here I am getting one more variable that is i, right? Now inside this loop, I need to multiply that base value. So I hope you understood why I wrote p here because p is deciding how many times we need to multiply the base. So basis right now to, so I'm writing r equals to r into d and closing this, right? And after completion of this, I'm going to print the result with the help of this r variable, right? And this is complete. Now I will explain this loop, how it is working. So basis to power is 3 and result is 1. Now i is starting from 1. So i is 1. i is less than equals to p. So it is true because i is 1 and p is 3. Then solve this r into b. So what is the initial value of r? That is 1. So 1 multiplied by b. So b is 2. So 2 into 1, new value of r will be 2. So now I hope you understood why r is initialized with 1 not 0. If we put 0 at the beginning, so this result will be 0. And the calculation result of this is stored inside r. So new value of r is now 2, right? So one, one rotation of this loop is completed and these are the figures of the one rotation of this loop. Now I will be incremented. So I will become 2. Now check this condition again. 2 less than equals to 3. So it is true. Again this calculation will be done. So right now r is 2 and b is also 2. So 2 into 2, 4 will be assigned into r. So new value of r will be 4. So now I hope you understood every time the value of r will be multiplied with this, so that new value can be generated. So first we multiply this. So 2 multiplied 1, result was 2. Now we multiply this 2. So 2 into 2. Right now result is 4. That is available in this r variable. Next time this result will be again multiplied with 2. So I will be incremented. Right now i is 3. So 3 less than b is 3. So it is again true. r is 4. So 4 into 2. Result is 8. That will be assigned into r. So now this is confirmed. So result is r. i will be again incremented. So i is now let's say 4. So 4 less than equals to 3. So this condition is false. Loop is terminated and this printf will be printing value of r with this. So result equals to 8 will be printed on output screen. So this way loop is repeating based on p and b is multiplied with r every time so that we can identify final result. So here we identified the result of 2 raise will be equals to 8 with the help of this loop. Now let's say if you want to calculate this, if you want to calculate this 2 raise 30. So I hope you easily understood this loop will repeat now 30 times and 30 times 2 will be multiplied with this r and after completion of this loop the result will be this. So with the help of loop we can reduce number of statements and calculation. So prefer to implement loops if you are repeating same set of instructions every time in C program. So I hope you understood how I explained you to calculate power. So don't use POW use this logic so that you can calculate a base and power result perfectly. And also remember this like a predefined POW is also available. So you can use that whenever required. So now you have two options either use POW that is predefined with the help of map.h header file or you can use this loop that is not requiring any header file. So it is custom implementation you can use that. So I hope you understood whatever I explained in this video. If you want to watch more programming related videos you can open my channel go to playlist and there are various programming related videos are available. So I hope you understood whatever I explained. Thank you for watching this video.