Conversion of Decimal Number to Roman Numeral.
What is Decimal Number and Roman Numeral?
Decimal number :- It is the standard system for denoting Integer and non-integer number. The numbers that may be represented in the decimal system are the decimal fraction. That is, fraction of the form a/10n, where a is an integer, and n is a non-negative integer.
Example :- 0,1,2,3,4,5,6,7,8,9…..
Roman Numeral:- It is a number system that originated in ancient Rome and remained the usual way of writing numbers throughout Europe well into the Late Middle Ages. Numbers in this system are represented by combinations of letters from the Latin alphabet. Modern usage employs seven symbols, each with a fixed integer value.
Example :- I, II, III, IV, V,X,L,C,D,M…
Programming:-
#include<stdio.h>
#include<conio.h>
int main()
{
int num;
printf("Enter the number");
scanf("%d",&num);
while(num>0)
{
if(num >= 1000)
{
printf("M");
num -= 1000;
}
else if(num >= 900)
{
printf("CM");
num -= 900;
}
else if(num >= 500)
{
printf("D");
num -= 500;
}
else if(num >= 400)
{
printf("CD");
num -= 400;
}
else if(num >= 100)
{
printf("C");
num -= 100;
}
else if(num >= 90)
{
printf("XC");
num -= 90;
}
else if(num >= 50)
{
printf("L");
num -= 50;
}
else if(num >= 40)
{
printf("XL");
num -= 40;
}
else if(num >= 10)
{
printf("X");
num -= 10;
}
else if(num >= 9)
{
printf("IX");
num -= 9;
}
else if(num >= 5)
{
printf("V");
num -= 5;
}
else if(num >= 4)
{
printf("IV");
num -= 4;
}
else
{
printf("I");
num -= 1;
}
}
getch();
return 0;
}
Output:-
Note:- If you did not understand or if you have any doubt then go to my YouTube Video and all videos are in Hindi Language.
Comments
Post a Comment