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
Strategy: 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’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[0].
- 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.
Under is the implementation of the code:
C++
|
Time Complexity: O(N)
Auxiliary Area: O(1)