Program to convert any given year into its roman equivalent by Function.



#include
main()
{
int year;
int convert (int year);

{

printf("Note:Enter a four year digit year.\n\n");
printf("Enter the year that you wanna convert to Roman: " );
scanf ("%d", &year);
if (year> 1999)

{
printf("Invalid Year.Please enter again.\n\n");
}
}

convert(year);
}


convert(int year)
{
int i;
printf("\nYear converted to Roman:");

i=(year/1000); //thousands place
if(i==1)
{
printf("m");
}
i=((year/100)%10); //hundreds place
switch (i)
{
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("dcccc"); //this part you may think is wrong..9 -> cm

break; //but i have taken a hint from the example in the question.

}



i=((year/10)%10); //tens place

switch(i)
{
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("lxxxx"); //had it not been for this example, it would have been xc
break;
}



i=year%10; //ones place

switch(i)
{
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;
}
printf ("\n\n");
return 0;
}




Related Links :

2 comments:

  1. ur program does not give proper output to a year of 2000+ year.

    ReplyDelete
  2. ohhh thnks i wll post updated program thnks

    ReplyDelete


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!