 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 check whether a number is having digits in ascending order or not. So here you can see two numbers are available in NBrival. So first is valid as per this caption and second is not valid. So now let's see how first is valid and second is invalid. So in first number if you see 1, 2, 3, 5, 7. So all the numbers are arranged in increasing order. So 1 after it, number 2 is available which is greater than 1, then V is greater than 2 and so on. Now after this, if we see this number 1, 2, 6, 3, 2. So here you can see 1, 2, 6, they are arranged in increasing order. But after 6, 3 and 2 are decreasing numbers. So as a whole this number is not arranged in ascending order. So if in a number all values are arranged in increasing order automatically. So that number is true as per our requirement and another one is false. So we need to print the output whether the number is arranged in ascending order or not. So now I'm going to write a solution for this. So I'm going to use these variables. So let's say I'm writing S1, S2 and I'm going to use a flag variable. Then printF. So this printF will display a message and enter a number. So we are going to read that number using scanF and that number will be stored inside and read it. Now with this and I need to check whether the number is arranged in ascending order or not. So let's say I'm taking this 1, 2, 3, 5, 7, 1, 2, 3, 5, 7. So I'm taking this as example. So our example is 1, 2, 3, 5, 7. So what I'm going to do, I'm going to first extract this number. So I'm moving from right to left. So if I have 7, so I need to check whether the next number that is previous to 7 is smaller to 7 or not. If it is smaller, then I need to check another number. Otherwise I can terminate the checking process. So first I'm going to identify that number with this S1 equals to n modulus 10. So n is 1, 2, 3, 5, 7. And if we apply modulus operation with 10, so always last visit will be received and that will be stored inside S1. Now I can write this n equals to n by 10. So if we divide any number by 10, so its last visit will be removed. So n is now having 1, 2, 3, 5, 7, 1. After this, I'm going to apply a loop which will check this n greater than 0. So if n is greater than 0, after doing this operation, if still n is greater than 0, then I'm going to write S2 equals to n modulus 10. So current value of n is 1, 2, 3, 5. So again we are applying modulus 10. So S2 will be having 5. So what we can do, here we can apply a if condition. So if S2 is greater than S1, if S2 is greater than S1, then we need to break the loop. Otherwise we can repeat the loop. So here I'm going to check this. If S2, S2 is the second number and S1 is the last number. So if this second last position is greater than last position, then we can break this loop. So here I'm going to use this flag. So if it is true, then flag will be 1 and I'm going to break this loop. If it doesn't happen, then I'm going to apply S1 equals to S2 and n equals to n by 10. And after completion of this loop, I have to check what is the value of f. So if f is 1, it means number is not aligned in ascending order. Otherwise it is. So after completion of this loop, I am writing if f equals to 0, then you can print ascending as you can print not in ascending order. So now I'm going to explain it completely. So here we identified S1. So S1 was 7 and was 1, 2, 3, 5 till here. Now check this condition. It is true. Then again check n modulus 10. So S2 will be having 5. Check this condition. S2 is greater than S1. No, S2 is 5. S1 is 7. So 5 is not greater than 7. So it will be 4. And we will be here. So I'm assigning S2 into S1. So S1 will be having 5 now. And n equals to n by 10. So this 5 will be removed and n will be having 1, 2, 3 only. So initially it was this, then it was this. And now it is 1, 2, 3. So every time we are removing last visit to this. So check this condition n is greater than 0 because it is 1, 2, 3. Perform this n modulus 10. So S2 will be having 3 now. S2 will be having 3 now. So check this 3 with 5. So S2 is 3. S1 is 5. So 3 greater than 5 again falls. We come here. S2 will be assigning to S1. So S1 will be 3 now. And perform n equals to n by 10. So now n will be 12. So 12 is greater than 0. Condition is true. Check this condition. S2 mod, sorry, n modulus 10. So 12 modulus 10. S2 will be having 2. Now check S2 with S1. So 2 greater than 3 falls. So again S2 will be assigned into S1 and will be divided by 10. So it will be 1. 1 is greater than 0, 2. 1 modulus 10. The meter will be 1. So S2 will be having now 1. Check this condition. Again it is false. So S1 will be having value of S2. So S1 will be having 1. Then again divide n by 10. So it will be 0. So this loop will not repeat. So you saw in this case, if we have this number, in this case, this if condition is always false. And if this condition is always false, then S will remain 0. Because S will convert into 1 when this condition will be true. But in that case, if condition is always false, so S will be 0. So this condition will be true and it will be assigned. Now if we take this example, 1, 2, 6, 3, 2. So in first time S1 will be having 2 as this number. And n will be having 1, 2, 6, 3. When we come here, so S2 will be having 3. Now check this. 3 greater than 2. So this is true. And f will be 1 and loop will be 7. And if f is 1, so it will not arrange in assignment. So this way you can check whether your number is having digits in assigning or not. So I hope you understood this logic, how I implemented it with the Anthropsy program. So if you want to watch more programming related videos, you can open my channel, go to playlist. And there you can find various programming related videos to watch them. And I hope whatever I explained in this video you understood. So thank you for watching this video.