Write a C program to interactively convert integers from Arabic numerals (e.g. \
ID: 3600637 • Letter: W
Question
Write a C program to interactively convert integers from Arabic numerals (e.g. "14") to Roman numerals (e.g. "XIV"). Your program should prompt the user to enter a number between 1 and 4999 (inclusive), then print the representation of that number in Roman numerals. After each successful conversion, the program should prompt the user for another number, until the user enters and invalid number (less than 1 or greater than 4999) or enters any non-numerical data (such as "exit") A sample-run of a model solution is shown below. Text in black is the output of the program and text in blue is user input Enter a number between 1 and 4999: 4 The value of 4 in Roman numerals is IV Enter a number between 1 and 4999: 33 The value of 33 in Roman numerals is XXXIII Enter a number between 1 and 4999: 61 The value of 61 in Roman numerals is LXI Enter a number between 1 and 4999: 123 The value of 123 in Roman numerals is CXXIII Enter a number between 1 and 4999: 789 The value of 789 in Roman numerals is DCCLXXXIX Enter a number between 1 and 4999: 652 The value of 652 in Roman numerals is DCLII Enter a number between 1 and 4999: 1234 The value of 1234 in Roman numerals is MCCXXXIV Enter a number between 1 and 4999: -1Explanation / Answer
#include<stdio.h>
#include<string.h>
void roman(int *n,int n1,int n2,char ch[])
{
if(*n>=n1&&*n<=n2)
{
*n=*n-n1;
printf("%s",ch);
}
}
int main()
{
int n;
printf("Enter number : ");
scanf("%d",&n);
printf("Roman Equivalent = ");
while(n>=1)
{
roman(&n,1,3,"I");
roman(&n,5,8,"V");
roman(&n,10,39,"X");
roman(&n,40,49,"XL");
roman(&n,50,89,"L");
roman(&n,90,99,"XC");
roman(&n,100,399,"C");
roman(&n,400,499,"CD");
roman(&n,500,899,"D");
roman(&n,900,999,"CM");
roman(&n,1000,5000,"M");
if(n==4)
{
printf("IV");
break;
}
if(n==9)
{
printf("IX");
break;
}
}
}
output:
Enter number : 69
Roman Equivalent = LXIX
Process returned 2 (0x2) execution time : 5.190 s
Press any key to continue.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.