Latest

6/recent/ticker-posts

HOW TO CONVERT DECIMAL TO ROMAN UPTO 10000000000 IN C and CPP

 HOW TO CONVERT DECIMAL TO ROMAN UPTO 10000000000 IN C and CPP

C: 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void roman(int a,int b)

{

     unsigned long int add=a+b;


    unsigned long int mult=a*b;

    printf("\naddition and multiplication in roman is\n");

    printf("HERE, '-' WRITTEN IN COMMON ROMAN NUMBERS IS REPLACED BY ' DUE TO TECHNICAL PROBLEM\n\n");

    long long int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000,4000,5000,9000,10000,40000,50000,90000,100000,400000,500000,900000,1000000,4000000,5000000,9000000,10000000,40000000,50000000,90000000,100000000,400000000,500000000,900000000,1000000000,4000000000,5000000000,9000000000,10000000000,};

    char ch_arr[41][10]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M","MV'","V'","MX'","X'","X'L'","L'","X'C'","C'","C'D'","D'","C'M'","M'","M'V''","V''","M'X''","X''","X''L''","L''","X''C''","C''","C''D''","D''","C''M''","M''","M''V'''","V'''","M''X'''","X'''"};


    int i=40;


    while(add>0)

    {

     unsigned long int div = add/num[i];

      add = add%num[i];



      while(div--)

      {

        printf("%s",ch_arr +i);

      }

      i--;

    }

    printf("\n\n");

    int j=40;

     while(mult>0)

    {

      unsigned long int div = mult/num[j];

      mult = mult%num[j];

      while(div--)

      {

        printf("%s",ch_arr +j);

      }

      j--;

    }

}

int main()

{

    int a,b;

    printf("enter a and b\n");

    scanf("%d%d",&a,&b);

   if((a*b)>10000000000)

    printf("ERROR");

    else

    roman(a,b);

  }

OUTPUT:

decimal to roman upto 1000000000

C++

#include <iostream>

 #include <string>

 using namespace std;


void roman(int a,int b)


{

     unsigned long int add=a+b;

     unsigned long int mult=a*b;


    cout<<"addition and multiplication in roman is"<<endl;


    cout<<"HERE, '-' WRITTEN IN COMMON ROMAN NUMBERS IS REPLACED BY ' DUE TO TECHNICAL PROBLEM\n\n";


    long long int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000,4000,5000,9000,10000,40000,50000,90000,100000,400000,500000,900000,1000000,4000000,5000000,9000000,10000000,40000000,50000000,90000000,100000000,400000000,500000000,900000000,1000000000,4000000000,5000000000,9000000000,10000000000,};


    string arr[41]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M","MV'","V'","MX'","X'","X'L'","L'","X'C'","C'","C'D'","D'","C'M'","M'","M'V''","V''","M'X''","X''","X''L''","L''","X''C''","C''","C''D''","D''","C''M''","M''","M''V'''","V'''","M''X'''","X'''"};

   int i=40;

   while(add>0)

  {

     unsigned long int div = add/num[i];

     add = add%num[i];

      while(div--)

     {

    cout<<arr[i];

     }

     i--;

    }

   cout<<endl<<endl;

   int j=40;

   while(mult>0)

  {

     unsigned long int div = mult/num[j];

     mult = mult%num[j];

     while(div--)

    {

     cout<<arr[j];

    }

    j--;

   }

  }

int main()

{


    int a,b;


    cout<<"enter a and b\n";


    cin>>a>>b;


   if((a*b)>10000000000)


    cout<<"ERROR"<<endl;


    else


    roman(a,b);

}

OUTPUT:

decimal to roman conversion in cpp


Post a Comment

0 Comments