#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void num2char(char **num, int bit, int n)
{
int i;
char low, mid, high;
char *p = *num;
switch (n) {
case 2:
low = 'C';
mid = 'D';
high = 'M';
break;
case 1:
low = 'X';
mid = 'L';
high = 'C';
break;
case 0:
low = 'I';
mid = 'V';
high = 'X';
break;
}
if (bit > 0) {
switch (bit) {
case 1:
case 2:
case 3:
for (i = 0; i < bit; i++) {
*p++ = low;
}
break;
case 4:
*p++ = low;
*p++ = mid;
break;
case 5:
*p++ = mid;
break;
case 6:
case 7:
case 8:
*p++ = mid;
for (i = 5; i < bit; i++) {
*p++ = low;
}
break;
case 9:
*p++ = low;
*p++ = high;
break;
}
}
*num = p;
}
static char roman_numeral[64] = { '\0' };
static char *intToRoman(int num)
{
int i;
char *p = &roman_numeral[0];
int thousand_bit = num / 1000;
int hundred_bit = (num % 1000) / 100;
int ten_bit = (num % 100) / 10;
int one_bit = num % 10;
if (thousand_bit > 0) {
if (thousand_bit < 4) {
for (i = 0; i < thousand_bit; i++) {
*p++ = 'M';
}
}
}
num2char(&p, hundred_bit, 2);
num2char(&p, ten_bit, 1);
num2char(&p, one_bit, 0);
*p = '\0';
return roman_numeral;
}
int main(int argc, char **argv) {
printf("%s\n", intToRoman(atoi(argv[1])));
return 0;
}
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
DdddJMs__135
- 粉丝: 2444
- 资源: 586
最新资源
- STM32单片机PWM输出完整C代码带注释简易版.docx
- STM32单片机PWM输出完整C代码带注释.docx
- system_file1711460535847
- 前端分析-202307110078
- 前端分析-202307110078
- 西门子S7-1200控制5轴伺服程序加维纶触摸屏画面案例 1.PTO伺服轴脉冲定位控制功能应用+速度模式应用+扭矩模式应用
- 案例程序5 伺服精准同步程序,西门子200 PLC与信捷DS2伺服通讯程序,可以实现同步运动 将编码器直接连接到伺服驱动器上
- jdk17安装包Windows x64
- ssm+mysql的学生选课管理系统(源码+lw+ppt)
- C#上位机与omron欧姆龙 Fins TCP通信以太网通讯实例 源码 通过和PLC用网络连接,可以读取写入欧姆龙PLC的数据寄
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)