Advertisement
Joao_Joao

Questão 89 Lista de Exercícios IFPB

May 14th, 2022
962
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void main() {
  4.   int num;
  5.   printf("Digite um numero entre 1 e 999: ");
  6.   scanf("%d", &num);
  7.  
  8.   printf("Seu valor correspondente em algarismos romanos eh: ");
  9.  
  10.   const int THIRD_DIGIT = num / 100;
  11.   switch(THIRD_DIGIT) {
  12.     case 0: break;
  13.     case 1: printf("C"); break;
  14.     case 2: printf("CC"); break;
  15.     case 3: printf("CCC"); break;
  16.     case 4: printf("CD"); break;
  17.     case 5: printf("D"); break;
  18.     case 6: printf("DC"); break;
  19.     case 7: printf("DCC"); break;
  20.     case 8: printf("DCCC"); break;
  21.     default: printf("CM"); break;
  22.   }
  23.  
  24.   const int SECOND_DIGIT = num % 100 / 10;
  25.   switch(SECOND_DIGIT) {
  26.     case 0: break;
  27.     case 1: printf("X"); break;
  28.     case 2: printf("XX"); break;
  29.     case 3: printf("XXX"); break;
  30.     case 4: printf("XL"); break;
  31.     case 5: printf("L"); break;
  32.     case 6: printf("LX"); break;
  33.     case 7: printf("LXX"); break;
  34.     case 8: printf("LXXX"); break;
  35.     default: printf("XC"); break;
  36.   }
  37.  
  38.   const int FIRST_DIGIT = num % 10;
  39.   switch(FIRST_DIGIT) {
  40.     case 0: break;
  41.     case 1: printf("I"); break;
  42.     case 2: printf("II"); break;
  43.     case 3: printf("III"); break;
  44.     case 4: printf("IV"); break;
  45.     case 5: printf("V"); break;
  46.     case 6: printf("VI"); break;
  47.     case 7: printf("VII"); break;
  48.     case 8: printf("VIII"); break;
  49.     default: printf("IX"); break;
  50.   }
  51.  
  52.   printf("\n");
  53. }
  54.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement