题目,s得到一个数,他想知道这个数每一位上的数字的孔数之和,其中,1,2,3,5,7这几个数字是没有孔的,0,4,6,9都只有一个孔,而8有两个孔。
c语言,打孔问题,求大神指导。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- cxlovu 2015-10-27 14:46关注
不知道是不是这个意思
#include <stdio.h> #include <stdlib.h> #include <string.h> int holeNum[10] = { 1, 0, 0, 0, 1, 0, 1, 7, 2, 1 } ; int getHoleNum(char* buff){ int res = 0; int len = strlen(buff); for(int i = 0; i < len; i++){ res += holeNum[buff[i] - '0']; } return res; } int main(){ int res; int size = 1024; char* buff = (char*)malloc(size); while(true){ printf("请输入数字:"); gets(buff); // printf("%s", buff); printf("该数字的洞数共有%d个\n", getHoleNum(buff)); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上