Converting integers to roman numerals

前端 未结 29 2294
走了就别回头了
走了就别回头了 2020-12-02 09:16

I\'m trying to write a function that converts numbers to roman numerals. This is my code so far; however, it only works with numbers that are less than 400. Is there a quick

29条回答
  •  有刺的猬
    2020-12-02 09:51

            Random r = new Random();
            int[] arreglo = new int[100];
            for (int i=0; i= 1000)
                {
                    Console.Write("M"); arreglo[t] -= 1000;
                }
                if (arreglo[t] >=900)
                {
                    Console.Write("MC"); arreglo[t] -= 900;
                }
                if (arreglo[t] >= 500)
                {
                    Console.Write("D"); arreglo[t] -= 500;
                }
                if (arreglo[t] >= 400)
                {
                    Console.Write("CD"); arreglo[t] -= 400;
                }
                if (arreglo[t] >= 100) {
                    Console.Write("C"); arreglo[t] -= 100;
                }
                if (arreglo[t] >= 90)
                {
                    Console.Write("XC"); arreglo[t] -= 90;
                }
                if (arreglo[t] >= 50)
                {
                    Console.Write("L"); arreglo[t] -= 50;
                }
                if (arreglo[t] >= 40)
                {
                    Console.Write("XL"); arreglo[t] -= 40;
                }
                if (arreglo[t] >= 10)
                {
                    Console.Write("X"); arreglo[t] -= 10;
                }
                if (arreglo[t] >= 9)
                {
                    Console.Write("IX"); arreglo[t] -= 9;
                }
                if (arreglo[t] >= 5)
                {
                    Console.Write("V"); arreglo[t] -= 5;
                }
                if (arreglo[t] >= 4)
                {
                    Console.Write("IV"); arreglo[t] -= 4;
                }
                if (arreglo[t] >= 1)
                {
                    Console.Write("I"); arreglo[t] -= 1;
                }
    
                Console.WriteLine();
    
            }
            Console.ReadKey();    
    

提交回复
热议问题