Created
July 26, 2015 17:01
-
-
Save SohanChy/bb16ff1db5c3cbdf771b to your computer and use it in GitHub Desktop.
Convert any given year to Roman Numerals in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void toroman(int y); | |
int main() | |
{ | |
toroman(1525); | |
return 0; | |
} | |
toroman(y) | |
{ | |
while(y>=1000) | |
{ | |
printf("m"); | |
y = y - 1000; | |
} | |
while(y>=500) | |
{ | |
printf("d"); | |
y = y - 500; | |
} | |
while(y>=100) | |
{ | |
printf("c"); | |
y = y - 100; | |
} | |
while(y>=50) | |
{ | |
printf("l"); | |
y = y - 50; | |
} | |
while(y>=10) | |
{ | |
printf("x"); | |
y = y - 10; | |
} | |
while(y>=5) | |
{ | |
printf("v"); | |
y = y - 5; | |
} | |
while(y>=1) | |
{ | |
printf("i"); | |
y = y - 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment