I am currently trying to write a program to simply output roman numerals (not convert-as on many previous threads) from 1-99..
This is the logic/code I have tried so far, but I am certain that it isn't correct apart from the fact that it isnt compiling.
#include<stdio.h>
int main(void)
{
int x[3],xfront,xback,i;
xfront=x/10;
xback=x%10;
switch (xback=x[2]) {
case '1' : printf("I");
break;
case '2' : printf("II");
break;
case '3' : printf("III");
break;
case '4' : printf("IV");
break;
case '5' : printf("V");
break;
case '6' : printf("VI");
break;
case '7' : printf("VII");
break;
case '8' : printf("VIII");
break;
case '9' : printf("IX");
break;
default : printf(" ");
}
switch (xfront=x[1]) {
case '1' : printf("X");
break;
case '2' : printf("XX");
break;
case '3' : printf("XXX");
break;
case '4' : printf("XL");
break;
case '5' : printf("L");
break;
case '6' : printf("LX");
break;
case '7' : printf("LXX");
break;
case '8' : printf("LXXX");
break;
case '9' : printf("XC");
break;
default : printf(" ");
}
for (x=1;x<=99;x++)
{
printf("%d%d",xfront,xback);
}
getchar ();
getchar ();
return 0;
}
For example when i declared variable x[3] i was referring to 3 spaces to store memory in _ _ \0, so that the first space will be the xfront and the second xback.
But when i wrote the loop i had to do the counter i.e. x from 1-99 and the compiler gave an error.
i tried to remediate to this by :
y=*x;
for (y=1;y<=99;y++)
{
printf("%d%d",xfront,xback);