49 lines
1.2 KiB
C
49 lines
1.2 KiB
C
#include <stdio.h>
|
|
|
|
// Struktur für eine römische Ziffer und ihren Wert
|
|
typedef struct {
|
|
int wert;
|
|
const char *roemisch;
|
|
} RoemZahl;
|
|
|
|
int main() {
|
|
// Array aufsteigend sortiert (klein nach groß), inkl. Super-Subtraktionsregeln
|
|
RoemZahl ziffern[] = {
|
|
{1, "I"},
|
|
{4, "IV"},
|
|
{5, "V"},
|
|
{9, "IX"},
|
|
{10, "X"},
|
|
{40, "XL"},
|
|
{49, "IL"}, // 50 - 1
|
|
{50, "L"},
|
|
{90, "XC"},
|
|
{99, "IC"}, // 100 - 1
|
|
{100, "C"},
|
|
{400, "CD"},
|
|
{499, "ID"}, // 500 - 1
|
|
{500, "D"},
|
|
{900, "CM"},
|
|
{990, "XM"}, // 1000 - 10
|
|
{999, "IM"}, // 1000 - 1
|
|
{1000, "M"}
|
|
};
|
|
const int n = sizeof(ziffern) / sizeof(ziffern[0]);
|
|
int zahl;
|
|
|
|
printf("Zu wandelnde Zahl: ");
|
|
scanf("%d", &zahl);
|
|
|
|
printf("... %d = ", zahl);
|
|
|
|
// Von groß nach klein durch das aufsteigende Array
|
|
for (int i = n - 1; i >= 0; i--) {
|
|
for (int j = 0; j < zahl / ziffern[i].wert; j++) {
|
|
printf("%s", ziffern[i].roemisch);
|
|
}
|
|
zahl %= ziffern[i].wert;
|
|
}
|
|
|
|
printf("\n");
|
|
return 0;
|
|
} |