M
hab das mal irgendwann gemacht, und zwar so:
typedef struct hilf{
int z;
char a,b;
}HILF;
void main()
{
int zahl=0,i,stelle=0;
char erg[20];
bool weiter=true;
HILF h[]= {
{1,'i',0},
{4,'i','v'},{5,'v',0},
{9,'i','x'},{10,'x',0},
{40,'x','l'},{49,'i','l'},{50,'l',0},
{90,'x','c'},{99,'i','c'},{100,'c',0},
{400,'c','d'},{490,'x','d'},{499,'i','d'},{500,'d',0},
{900,'c','m'},{990,'x','m'},{999,'i','m'},{1000,'m',0}
};
if (scanf("%i",&zahl))
{
while (zahl>0)
{
for(i=18;i>=0 && weiter;i--)
if(h[i].z<=zahl)
{
erg[stelle++]=h[i].a;
if (h[i].b)
erg[stelle++]=h[i].b;
zahl-=h[i].z;
weiter=false;
}
weiter=true;
}
erg[stelle]=0;
printf("Ergebnis: %s\n",erg);
system("cls");
}
}