 Hello friends, I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can find out maximum and minimum value from an area, right? So before starting the explanation, if you want to watch more programming related videos, you can go to description or detail of this video and there you will find various links of place or you can follow them. Now I'm going to start the explanation how we can implement this in C language. So we need to implement an array so that we can find out maximum and minimum. So for example, I am going to implement an array of 10 elements, right? So array will be having 10 elements and from those elements, one will be maximum and one will be minimum that I need to edit. So now I'm going to start writing the program. So first of all, main, inside main, I'm going to declare an array. So we need to declare size of arrays 10 because we are going to process it on 10 elements. If you want to process it on more elements, then you can increase this size of array, right? Then variable i so that I can process a loop. Then a variable max which will be initialized with 0 and a variable min which will be initialized with 3, 2, 7, 6, 7. Right? So now you might be thinking like max I have initialized with 0 and min I have initialized with 3, 2, 7, 6, 7. So those 10 elements that we are going to receive from user, we are assuming that they all will be positive numbers. The array will be storing only positive numbers, right? So now imagine if max is 0, if max is 0 initially, it means whatever elements will be available in the array, they may be equal to 0 or greater than 0. They may not be less than 0. So that's why this is the minimum value and which is initialized with max so that we can easily identify who is the maximum value. Now min is 3, 2, 7, 6, 7. Let's say if I initialize 0 inside min. So if we consider all positive numbers, so 0 is also a positive and it is the smallest positive number. So if initially I put 0 into min, so it always will be minimum. No other number can be assigned into min. So that's why I put maximum value on min and minimum value in max so that we can identify the proper number. Okay. So now I'm going to leave the elements. So the masses will be entered 10 numbers. Then a for loop. This for loop will repeat 10 times so that we can read 10 numbers. Now inside this, I am writing a scanf. So here you can see this scanf is reading AO5. So I is initially 0. So every time a value of 5 will be incremented by 1. So first it will receive value of a0, then a1, then a2, then a3. So by going 10 times, it will be receiving 10 different numbers into n. Now after reading elements, we can apply this condition here. So now I need to compare this array element with max and min. So if AO5 is greater than max, if element of array is greater than max, it means the array element should be the next maximum. So here I can write max equals to AO5. Here I can write max equals to AO5. So if array element is greater than max, then array element will be assigned into max. So after completion of this implementation, I will be taking an example. So I will create 10 elements array and then we will go with this program so that we can check whether it is working fine or not. So after this if I am going to implement another if. So this if condition will be for minimum. So if AO5 is less than min, then min equals to AO5. So if array element is less than minimum, so we need to assign array element into min variable. And then we can close this program. Now imagine that if minimum is 0, so if we compare array element with min and all positive numbers are there, so this condition will not be true. This won't be true ever because min is 0 and 0 is the smallest element. So array element will not be less than min anytime. So that's why I didn't put 0. Instead I mentioned 3, 2, 7, 6, 7 and give the largest value. Now after completion of this loop, it will repeat 10 times. So it will receive 10 different numbers. Those will be checked for max and those will be checked for min as well. So after completion of this loop, you can write a printf which will print maximum, minimum. So here I am going to write max and min. So with the help of these two variables, maximum and minimum will be printed and then you can close your min function. So this way I implemented this loop. Now I am going to create an array. So these are 10 elements. These are indexes. So these are indexes 0, 1, 2, 3, up to 9 and now I am putting some value. So this way these 10 numbers are available in array. So let's say first time I will be entering 15. So max is 0 and min is this. Now I am inside this loop. So first number will go to 0 index inside A0. Now I am going to compare A0 with max. So A0 is 15 and max is below. So this condition is true because array element is greater than max. So here I am assigning array element into max. So array element is 15. So new value of max will be new value of max will be 15. Now come to this condition. So array element is 15. Min is 3, 2, 7, 6, 7. So again it is true. So array element will be assigned into min. So right now max is 15 and min is 15. Now imagine if min is 0, if min is initially 0. So this condition will not be true here. Because A of i is 15, min is 0. So this will not be true. And in any case that condition won't be true. So that's why don't put 0 and min for the highest element and min. And the lowest element in max. Now i will be implemented. So next time suppose I entered 5 in A1 position. So check this condition A of i greater than max. So A of i means 5 and max is 15. So it is false. So this assignment won't work. Come to this condition. A of i is 5 and min is 15. So it is true. So 5 will be assigned into min. So new value of min is now 5. Then again i will be implemented. So let's say next time i entered 20. So again check this condition. 20 greater than max. So max is 15 and A of i is containing 20. So this is now true. So max will be having new value as 20. Now check this condition A of i. So A of i is 20 and min is 5. So it is false. 20 is not less than 5. So it won't work. And again i plus plus will be performed. So next number is 17. 17 will be checked with 20. So 17 is not greater than 20. So it is false. Then 17 is less than 5. It is also false. So in case of 17. In case of 17. Both condition will be false. Because 17 is not greater than 20. And 17 is not greater than sorry. 17 is not less than 5. So it won't assign anywhere. So this way step by step we need to compare all the values. And accordingly you need to assign the value. And if we go further. So next number is 20. So 20 greater than 20. Again it is false because it is also having 20. So if same numbers are available. Then also nothing will happen. Condition will be false. Because if we assign same number again. So it makes no change. So that's why I didn't put equals to sign here. So this way you see the program is working fine. It is properly calculating max and min value. So after completion of 10 rotation. Whatever will be the value of max and min. Will be printed with the help of this printer. So I hope with this explanation you understood how with a single program. We can identify maximum and minimum value from 1D editing. So implement this program so that you can feel like how it will be executing. While you will be implementing it with the help of C compiler. So I hope you understood whatever I explained in this video. Thank you for watching this video.