当前位置:网站首页>C语言 写出这个数
C语言 写出这个数
2022-06-30 01:25:00 【Martin の Blog】
算法设计思路
- 定义数字字母列表
- 使用get方法读取字符串,并进行单个字符转数字相加得到值n
- 遍历n值,将n的各个位数保持在列表t中
- 通过列表t中的值进行数字字母列表的打印
代码
#include <stdio.h>
#include <string.h>
int main(){
char c [105];
int a [5];
char pinyin[][9] = {
"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
int i, n, t;
n = 0;
t = 0;
gets(c);
for(i=0; i<strlen(c); i++){
n += c[i] - '0';
}
while(n != 0){
a[t] = n % 10;
n = n / 10;
t++;
}
printf("%s", pinyin[a[t-1]]);
for(i=t-2; i>=0; i--){
printf(" %s", pinyin[a[i]]);
}
return 0;
}
运行结果
边栏推荐
猜你喜欢
【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类
城市规划馆在设计制作上需要注意什么
Sklearn notes: make_ Blobs generate clustering data
What if you can't write your composition well? Ape counseling: parents should pay attention to these points
js逆向请求参数加密:
画画水族馆的应用特色及功能
In depth analysis of a large number of clos on the server_ The root of wait
The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
Ansible ad-hoc 临时命令
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
随机推荐
Storage engine analysis
Varnish 基础概览5
Varnish 基础概览4
【535. TinyURL 的加密与解密】
Stringredistemplate disconnects and the value disappears
Varnish 基础概览6
Analysis of natural frequency and buckling load of cylinder by finite element method
【推荐系统】基于用户的协同过滤简明原理与代码实现
首届技术播客月开播在即
Varnish 基础概览1
挖财的课程靠谱吗,让开户安全吗?
Varnish 基础概览3
Varnish 基础概览10
Vant weave - remove (clear) < van button > button component Click to display gray background effect
The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
一文读懂,MES管理系统模块功能
Three text to speech artifacts, each of which is very practical
浅析现代Web端im即时通讯开发技术
The 8th "Internet +" competition - cloud native track invites you to challenge
TP-LINK configure WiFi authentication method for wireless Internet SMS