3. 輸入一個正整數求出它是幾位數:輸出原數和位數。


 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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM