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

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...
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
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,...
I have a question about C++ programming Language class. I am confused with these terms and...
I have a question about C++ programming Language class. I am confused with these terms and what they are for. 1. Unix 2. Terminal 3. Git 4. CLOC 5. Linux Please explain each words and what's their jobs for C++. Also, if you know some good sources/websites, could you please provide me a link where I can learn how to use Unix, Terminal, Git, etc.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT