Given a quantity N. Convert N into an Indian forex format. For extra understanding, please look into examples.
Enter: N = 1000000
Output: Rs 10, 00, 000
Enter: N = 1500
Output: Rs 1, 500
Strategy: Steps concerned within the implementation of code:
- We have to test 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’ll merely return it else we’ll do the next, newString = “”.
- if the size is odd:
- we’ll the primary character into a brand new string newSstring = N.
- after which we’ll and commas new string = “, “.
- Now we’ll skip the 2 characters after which add “, ” until the size < n-2.
- And ultimately, we’ll add the remaining characters to the newString.
Beneath is the implementation of the code:
Time Complexity: O(N)
Auxiliary Area: O(1)