Monday, January 7, 2013

Program to Convert Decimal to Roman Number



C/C++ Program to Convert Decimal to Roman Number



#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int a;

     cout<<"      \" This program will convert decimal number into roman number. \""<<endl<<endl;

     xx:
    cout<<"What is the Decimal number ?. Give a integer number."<<endl;
    cin>>a;

    if(a<0) {
    cout<<"Negative number is not allow.Please give a integer number."<<endl;
    goto xx;
    }

     cout<<endl;
     cout<<"You have given decimal "<<a<<endl;
     cout<<"In Roman number is : ";

     while(a>=1000){
    cout<<"M";
    a=a-1000;
    }

     while(a>=500){
    cout<<"D";
    a=a-500;
    }

     while(a>=100){
    cout<<"C";
    a=a-100;
    }

     while(a>=50){
    cout<<"L";
    a=a-50;
    }

     while(a>=10){
    cout<<"X";
    a=a-10;
    }

     if((a>=5) && (a<9)){
    cout<<"V";
    a=a-5;
    }

     switch(a){
     case 0 :
        break;

     case 1 : cout<<"I"  ;
        break;

     case 2 : cout<<"II" ;
        break;

     case 3 : cout<<"III";
        break;

     case 4 : cout<<"IV" ;
        break;

     case 9 : cout<<"IX" ;
        break;
     }

getch();
}




For more please visit cybarlab.com

No comments:

Post a Comment