首页 > 其他 > 详细

3. 输入一个正整数求出它是几位数:输出原数和位数。

时间:2021-06-10 12:03:48      阅读:19      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 int digit;
 6 
 7 int main(void) {
 8     void count(string str);
 9     printf("Please input numbers:\n");
10     string text;
11     cin >> text;
12     count(text);
13     cout << "原数: " << text << endl;
14     cout << "位数" << digit << endl;
15     return 0;
16 }
17 
18 void count(string str) {
19     int i;
20     for (i = 0; str[i] != \0; i++) {
21         if (str[i] >= 0 && str[i] <= 9) {
22             digit++;
23         }
24     }
25 }

 

3. 输入一个正整数求出它是几位数:输出原数和位数。

原文:https://www.cnblogs.com/yj2434/p/14869499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!