int ConvertToRomanNo(int number,int no,char ch);
int main()
{
int number=525;
printf("Roman number of" " %d " "is::",number);
number=ConvertToRomanNo(number,1000,'M');
number=ConvertToRomanNo(number,500,'D');
number=ConvertToRomanNo(number,100,'C');
number=ConvertToRomanNo(number,50,'L');
number=ConvertToRomanNo(number,10,'X');
number=ConvertToRomanNo(number,5,'V');
number=ConvertToRomanNo(number,1,'I');
return 0;
}
int ConvertToRomanNo(int number,int no,char ch)
{
int i,j;
if(number==9)
{
printf("IX");
return (number%9);
}
if(number==4)
{
printf("IV");
return (number%4);
}
j=number/no;
for(i=1;i<=j;i++)
{
printf("%c",ch);
}
return(number%no);
}
TC O(n)
SC o(1)
Run Here https://ideone.com/xvqDz
No comments :
Post a Comment