training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

dec2rom.c (1381B)


      1 /* Esercizio 4.33 */
      2 
      3 #include <stdio.h>
      4 
      5 int main()
      6 {
      7    int i, j;
      8 
      9    printf("Decimale\tRomani\n");
     10 
     11    for(i = 900; i < 1000; ++i) {
     12 
     13       printf("%d\t\t", i);
     14 
     15       if (i < 10)
     16 	 j = i;
     17       else
     18 	 j = i / 1 % 10;
     19 
     20       switch(i / 10 % 10) { /* decine */
     21          case 1:
     22             printf("X");
     23             break;
     24          case 2:
     25             printf("XX");
     26             break;
     27          case 3:
     28             printf("XXX");
     29             break;
     30          case 4:
     31             printf("XL");
     32             break;
     33          case 5:
     34             printf("L");
     35             break;
     36          case 6:
     37             printf("LX");
     38             break;
     39          case 7:
     40             printf("LXX");
     41             break;
     42          case 8:
     43             printf("XXC");
     44             break;
     45          case 9:
     46            printf("XC");
     47            break;
     48       } /* end of switch (decine) */
     49 
     50       switch(j) { /* unità */
     51 	 case 1:
     52 	    printf("I");
     53 	    break;
     54 	 case 2:
     55 	    printf("II");
     56 	    break;
     57 	 case 3:
     58 	    printf("III");
     59 	    break;
     60 	 case 4:
     61 	    printf("IV");
     62 	    break;
     63 	 case 5:
     64 	    printf("V");
     65 	    break;
     66 	 case 6:
     67 	    printf("VI");
     68 	    break;
     69 	 case 7:
     70 	    printf("VII");
     71 	    break;
     72 	 case 8:
     73 	    printf("VIII");
     74 	    break;
     75 	 case 9:
     76 	    printf("IX");
     77 	    break;
     78 
     79       } /* end of switch (unit) */
     80 
     81       printf("\n");
     82    }
     83 
     84    printf("%d\t\tC\n", i);
     85 
     86    return 0;
     87 } /* E0F main */
     88