C Program For Roman Number

#include<stdio.h>
#include<string.h>

int main()
{
    int dec[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
    char *rom[]= {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    int givennumber,i;
    char romannumber[500] = "";
    printf("\nENTER A POSITIVE INTEGER NUMBER\n");
    scanf("%d",&givennumber);
   
    for(i = 0;i<13;i++)
    {
        while(givennumber >= dec[i])
        {
            givennumber = givennumber - dec[i];
            strcat(romannumber,rom[i]);
        }
    }
    printf("\nroman number is = %s\n",romannumber);
    return 0;
}



Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment