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. 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...
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
The following is for C programming language: I want to scan for initials in a line...
The following is for C programming language: I want to scan for initials in a line of text. my line of text is as follows: 12345 3.5000 a j 12346 4.1000 s p The first number represents the student ID, the second number represents the gpa, the third character represents the first initial and the fourth character represents the last initial of the student. My text file contains these values. The following is my code: fscanf(fp, "%d %c %c", &studentID,...
I am building a game in C programming language where I need to add objects of...
I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit. I have the following 2 functions to start with: ```int add_object_vert(int r,...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
if I need to get the sum of 6 numbers, here is a C programming solution...
if I need to get the sum of 6 numbers, here is a C programming solution int getSum(int number1, int number2, int number3, int number4, int number5, int number6); and the function is: int SUM; sum = number1+number2+number3+number4+number5+number6; return SUM; this function is called in main, and the main looks like: int totalSum; totalSum=getSum(1,2,3,4,5,6); while(1); so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can...
How do I add additional command line arguments in C++? I am working on a programming...
How do I add additional command line arguments in C++? I am working on a programming assignment that has the user input a file into the command line and then they have the option to also add a series of other arguments to the command line. I know how to accept the text file from the command line by using: int main(int argc, char *argv[]) { /.../ } Then filename(argv[1]) would be the text file that they put into the...
1.Determine whether S spans V . Justify your answers. V = C ^0 [−1, 1] (the...
1.Determine whether S spans V . Justify your answers. V = C ^0 [−1, 1] (the vector space of continuous functions on [−1, 1]) and S = {1, t, t2 , t3 , . . . }. 2.Let S be a set in a vector space V and v any vector. Prove that span(S) = span(S ∪ {v}) if and only if v ∈ span(S).
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 2? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 3? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT