Decimal 1 5 10 50 100 500 1000 Roman i v x l c d m
Roman equivalent of 1988 is mdccclxxxviii. Roman equivalent of 1525 is mdxxv.
#include<stdio.h> #include<conio.h> int main(){ clrscr(); int yr,i,j=0; char roman[20]; printf("Enter Year : "); scanf("%d",&yr); if(yr/1000>=0) { for(i=0;i<(yr/1000);i++) { roman[j]='m'; j++; } yr = yr - (i+1)*1000; } if(yr/500>=0) { for(i=0;i<(yr/500);i++) { roman[j]='d'; j++; } yr = yr - (i+1)*500; } if(yr/100>=0) { for(i=0;i<(yr/100);i++) { roman[j]='c'; j++; } yr = yr - (i+1)*100; } if(yr/50>=0) { for(i=0;i<(yr/50);i++) { roman[j]='l'; j++; } yr = yr - (i+1)*50; } if(yr/10>=0) { for(i=0;i<(yr/10);i++) { roman[j]='x'; j++; } yr = yr - (i+1)*10; } if(yr/5>=0) { for(i=0;i<(yr/5);i++) { roman[j]='v'; j++; } yr = yr - (i+1)*5; } if(yr/1>=0) { for(i=0;i<(yr/1);i++) { roman[j]='i'; j++; } } printf("year in roman : "); for(i=0;i<=j;i++) printf("%c",roman[i]); getch(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)