Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Created July 26, 2015 17:01
Show Gist options
  • Save SohanChy/bb16ff1db5c3cbdf771b to your computer and use it in GitHub Desktop.
Save SohanChy/bb16ff1db5c3cbdf771b to your computer and use it in GitHub Desktop.
Convert any given year to Roman Numerals in C
#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