Given a quantity N. Convert N into an Indian foreign money format. For extra understanding, please look into examples.
Examples:
Enter: N = 1000000
Output: Rs 10, 00, 000Enter: N = 1500
Output: Rs 1, 500
Method: Steps concerned within the implementation of code:
- We have to examine whether or not the size of the string is even or odd.
- If the size of the string is lower than equal to three we are going to merely return it else we are going to do the next, newString = “”.
- if the size is odd:
- we are going to the primary character into a brand new string newSstring = N[0].
- after which we are going to and commas new string = “, “.
- Now we are going to skip the 2 characters after which add “, ” until the size < n-2.
- And ultimately, we are going to add the remaining characters to the newString.
Under is the implementation of the code:
C++
|
|
Time Complexity: O(N)
Auxiliary House: O(1)