Friday, August 16, 2019

Decimal To Roman Numeral Converter Using Pointers in Golang

Write a program that will ask the user to give a  decimal number and then the program will convert the given number into  the roman numeral  equivalent value using pointers/

Decimal Roman
1         I  
4           IV
5         V
9         IX
10         X
40     XL
50          L
90         XC
100         C
400         CD
500         D
900        CM
1000 M

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com


Sample Program Output



Program Listing

/* roman_numeral.go
Author   : Mr. Jake Rodriguez Pomperada, MAED-IT
Date     : August 8, 2019  Thursday   4:30 PM
Location : Bacolod City, Negros Occidental
Website  : http://www.jakerpomperada.com
Emails   : jakerpomperada@gmail.com and jake_pomperada@tup.edu.ph
*/

package main

import (
"fmt"
)

func DecimalToRoman(num int) string {
values := []int{
1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4, 1,
}

symbols := []string{
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"}
roman := ""
i := 0
for num > 0 {
k := num / values[i]
for j := 0; j < k; j++ {
roman += symbols[i]
num -= values[i]
}
i++
}
return roman
}

func main() {

var val_num int

fmt.Print("\n")
fmt.Print("\tDecimal To Roman Numeral Converter Using Pointers")
fmt.Print("\n\n")
fmt.Print("\tGive a Number     : ")
fmt.Scanf("%d",&val_num)

val_num2 := &val_num

result := DecimalToRoman(*val_num2)

fmt.Print("\n")
fmt.Printf("\tThe roman numeral value of %d is %s.",val_num,result)
fmt.Print("\n\n")
fmt.Print("\tEnd of Program")
fmt.Print("\n")
}







No comments:

Post a Comment