www.flickr.com

C PROBLEM: MAKE A PROGRAM THAT WILL CONVERT A NUMBER INTO ROMAN NUMERALS

Sunday, April 17, 2011 Posted by Glenn

/*C PROBLEM: MAKE A PROGRAM THAT WILL CONVERT A NUMBER INTO ROMAN NUMERALS

-program by spoon feed */

#include

#include

main()

{

int n,r,th,h,t,o;

printf("Enter a number less 1-1000: ");

scanf("%d", &n);

if (n>1000)

{

n=0;

printf("invalid input");

}

else if (n<=1000)

{

th=n/1000;

n=n%1000;

h=n/100;

n=n%100;

}

/*If the input number is 11 - 19

this code will be executed*/

if ((n>10) && (n<20))

{

t=0;

o=0;

r=n%10;

}

else

{

t=n/10;

n=n%10;

o=n;

}

switch(th)

{

case 1: printf("M"); break;

}

switch(h)

{

case 1: printf("C"); break;

case 2: printf("CC"); break;

case 3: printf("CCC"); break;

case 4: printf("CD"); break;

case 5: printf("D"); break;

case 6: printf("DC"); break;

case 7: printf("DCC"); break;

case 8: printf("DCCC"); break;

case 9: printf("CM"); break;

}

switch(r)

{

case 1:printf("XI");break;

case 2:printf("XII");break;

case 3:printf("XIII");break;

case 4:printf("XIV");break;

case 5:printf("XV");break;

case 6:printf("XVI");break;

case 7:printf("XVII");break;

case 8:printf("XVIII");break;

case 9:printf("XIX");break;

}

switch(t)

{

case 1:printf("X");break;

case 2:printf("XX");break;

case 3:printf("XXX");break;

case 4:printf("XL");break;

case 5:printf("L");break;

case 6:printf("LX");break;

case 7:printf("LXX");break;

case 8:printf("LXXX");break;

case 9:printf("XC");break;

}

switch(o)

{

case 1:printf("I");break;

case 2:printf("II");break;

case 3:printf("III");break;

case 4:printf("IV");break;

case 5:printf("V");break;

case 6:printf("VI");break;

case 7:printf("VII");break;

case 8:printf("VIII");break;

case 9:printf("IX");break;

}

getch();

}

glenn von

Author: Glenn Posadas

20 year old 5th year Computer Engineering Student, a blogger, photographer, programmer, and an electronics hobbyist; a Christian who loves God very much..

Sharing is so Easy:
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google Twitter FaceBook

  1. Anonymous

    hi. are you online?
    I really neeeed help in basic Roman numeral programming.. tomorrow's our midterm. have time to help? :O

  2. hi anonymous, I found out so late that you have dropped a comment here. sad. Im very sorry, anyways, how was your exam? C and C++ is so easy :) any questions?

Post a Comment

Drop a comment. Thank you guys!