• Follow Us

C Program to Convert Numbers to Roman Numerals

Let’s have a look at how to Convert Number to Roman Number in C Programming Language.

C Program to Convert Numbers to Roman Numerals

#include <stdio.h>

/*Learn C Programming at CodeAtGlance.com*/

  int main () {

        int number;

        printf("Enter your input:");

        scanf("%d", &number);

        printf("Roman Number: ");

        while (number > 0) {

                if (number >= 1000) {

                        /* M - 1000 */

                        printf("M");

                        number = number - 1000;

                } else if (number >= 500) {

                        if (number >= 900) {

                                printf("CM");

                                number = number - 900;

                        } else {

                                printf("D");

                                number = number - 500;

                        }

                } else if (number >= 100) {

                        if (number >= 400) {

                                printf("CD");

                                number = number - 400;

                        } else {

                                printf("C");

                                number = number - 100;

                        }

                } else if (number >= 50) {

                        if (number >= 90) {

                                printf("XC");

                                number = number - 90;

                        } else {

                                printf("L");

                                number = number - 50;

                        }

                } else if (number >= 9) {

                        if (number >= 40) {

                                printf("XL");

                                number = number - 40;

                        } else if (number == 9) {

                                printf("IX");

                                number = number - 9;

                        } else {

                                printf("X");

                                number = number - 10;

                        }

                } else if (number >= 4) {

                        if (number >= 5) {

                                printf("V");

                                number = number - 5;

                        } else {

                                printf("IV");

                                number = number - 4;

                        }

                } else {

                        printf("I");

                        number = number - 1;

                }

        }

        printf("\n");

  }

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart