Coders Packet

Roman numeral to integer number converter in C++

By Muskan Chaturvedi

In this program with the help of c++ language ,a roman numeral can be converted into corresponding integer number.

snapshot of source code  Source code of function used  

The first image shows a function that returns the numeric value of respective roman numerals. And the second image shows a parametrized function that takes string as an input and returns the numeric value of roman numeral. A for loop is used to iterate through the string. Further if-else statement is used to check the conditions.

ALGORITHM USED:

1)If the character of that string belongs to the character given in the num() function then simply return the value of that character and add it to the sum variable.

2)Else if the value of present character is greater than its next character we simply add the value of present character to the sum variable.

3)In the next step if the value of present character is less than the next character, we subtract the numeric value of the next character with present character and add the result to sum.

Time complexity- O(n)   [As we iterate the string only once]

Space complexity-O(1)   [As no extra space is used]

OUTPUT-

output

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Muskan Chaturvedi (Muskan01)

Download packets of source code on Coders Packet