Question

In: Computer Science

***C PROGRAMMING*** Roman Numerals: I           =          1 V          =       

***C PROGRAMMING***

Roman Numerals:

I           =          1

V          =          5

X          =        10

L          =        50

C          =      100

D          =      500

M         =     1000

Use % for modulus division.

Step 1

  • Write a program that will and display 3 menu options. The options are:
  1. Display the first 50 Roman Numerals.
  2. Enter a number to be converted to Roman Numerals.
  3. Exit.
  • Prompt the user for a selection: A, B or C.
  • If the user selects A then print 2 Columns of numbers on the screen. The leftmost column will display the roman numerals for numbers 1 – 25 and the rightmost column will display the roman numerals for number 26 – 50.

For example:

Number/Numeral                                                            Number/Numeral

1 = I                                                                              26 = XXVI

2 = II                                                                             27 = XXVII

3 = III                                                                            28 = XXVIII

4 = IV                                                                           29 = XXIX

5 = V                                                                            30 = XXX

.

.

.

25 = XXV                                                                      50 = L

Press any key to continue?

  • If the user selects B then prompt the user for a number between 1 and 3999 and then display the roman numeral. Only allow positive integers between 1 and 3999. Loop until a valid number is entered
  • If the user selects C then end the program.

Solutions

Expert Solution

Code

#include <stdio.h>

void rom(int a) //prints roman value of the number
{
    int n[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
    char* r[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
    int i=12;
    while(a>0)
    {
      int div = a/n[i];
      a = a%n[i];
      while(div--)
      {
        printf("%s",r[i]);
       // strcat(res,r[i]);
      }
      i--;
    }
    printf("\n");
}
int main()
{
  char ch;
  while(1)
  {
    printf("A. Display the first 50 Roman Numerals.");
    printf("\nB. Enter a number to be converted to Roman Numerals.");
    printf("\nC. Exit");
    printf("\nEnter A or B or C\n");
    scanf(" %c",&ch);
    if(ch=='C') //C to exit
      break;
    if(ch=='A') //A to print 50 roman valies
    {
      for (int i=1;i<=25;i++)
      {
        printf("%d=",i);
        rom(i);
        printf("\t\t\t\t%d=",i+25);
        rom(i+25);
        printf("\n");
      }
    }
    if(ch=='B') //B to print desired value of number
    {
      printf("Enter number between 1 to 3999\n");
      int n;
      while(1)
      {
        scanf("%d",&n);
        if(n<1 || n>3999)
        {
          printf("Enter number between 1 to 3999\n");
        }
        else
          break;
      }
      rom(n);
    }
  }
  return 0;
}

Terminal Work

.


Related Solutions

1.13. Problem. (Section 3.4) Three black boxes are labeled with Roman numerals I, II and III....
1.13. Problem. (Section 3.4) Three black boxes are labeled with Roman numerals I, II and III. • Box I contains four red chips and three blue chips. • Box II contains two red chips and five blue chips. • Box III contains seven red chips and no blue chips. Solve each of the following problems. (a) Suppose a box is selected at random and three chips are drawn at random from the box. If all three chips are red, what...
Exercise 1: Write a program that converts a number entered in Roman numerals to decimal. Your...
Exercise 1: Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, say, Roman. An object of type Roman should do the following: Store the number as a Roman numeral. Convert and store the number into decimal. Print the number as a Roman numeral or decimal number as requested by the user. The decimal values of the Roman numerals are: M 1000 D 500 C 100 L 50 X 10...
Assignment 5: Roman Numerals Assignment 5 You must create an application that takes two integer values,...
Assignment 5: Roman Numerals Assignment 5 You must create an application that takes two integer values, adds them together, and then displays the result of that expression as a roman numeral. Create a two Python scripts: 1. Name your first script roman_numerals.py 2. Name your second script user_input.py 3. The goal of this projects is to practice the principles of abstraction while adding in an element of selection. How much you abstract your code is up to you, but you...
I need C++ programming with output. I have tried other programming and it does not work....
I need C++ programming with output. I have tried other programming and it does not work. So please give me the one that actually works. Assignment 1 Design your own linked list class that works as a template class. It should provide member functions for appending, inserting and deleting nodes. The destructor should destroy the list. The class should also provide a member function that will display the contents of the list to the screen. The class should also provide...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get for loops, and wanted help with this question. How do I go about it? 1a. Write a program to ask the user for the starting balance of their savings account, what interest rate they are earning, and how many years they are planning to keep the account open. To calculate the new balance, including compounded interest: use a for loop to loop through the...
1. For each of the following production functions (a-c) answer the following questions (i-v): i) Calculate...
1. For each of the following production functions (a-c) answer the following questions (i-v): i) Calculate the marginal products MPL and MPK. ii) Calculate MRTSL;K and determine if this is diminishing as good L increases. iii) If Q0 = 100, w = 8 and r = 2, determine long-run cost minimizing combination of labor and capital and the associated total cost. iv) If Q0 = 100, w = 8 and r = 2, determine short-run cost minimizing combination of labor...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to 10 digits. If the result of the addition is more than 10 digits long, then simply give the output message "Addition overflow" and not the result of the addition. Use arrays to store hexadecimal numerals as arrays of characters. Input Notes: The program reads two strings, each a sequence of hex digits (no lowercase, however) terminated by a "q". Example: 111q AAAq Output Notes...
In C programming, I am trying to search for the names of people that in this...
In C programming, I am trying to search for the names of people that in this DOISigned.txt file, however I am having trouble getting the first and last names of the multiple people named john, my current code only searches for John once and then it terminates,here is my current code #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUF_SIZE 0x3000 char buf[BUF_SIZE]; int main() {    char* inputFile = "DOISigners.txt";    FILE* fp;    fp = fopen(inputFile, "r");...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
This is a question about C# programming: True / False questions: for (int i=5; i <...
This is a question about C# programming: True / False questions: for (int i=5; i < 55; i+=5) { decimal decPrcPerGal = decGalPrc + i; decPayPrc = iBuyGall * decPrcPerGal; if (decPrcPerGal > decMAX_GALPRC) { continue; } if (decPrcPerGal > decMAX_GALPRC) { break; } Console.WriteLine(" {1} gallon(s) at {0,3} would cost {2,8:$###,##0.00}", decPrcPerGal, iBuyGall, decPayPrc); } In the code above: 1. If decGalPrc is 10.57 decPrcPerGal will always be some number of dollars and 57 cents   True/ False? 2. In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT