C 演算法中遇到的問題

2021-09-11 16:14:42 字數 946 閱讀 8483

最近在用c++練習程式設計演算法,其中乙個問題:列印從1到最大的n位數。用遞迴的數字排列方法做,本來已經能成功做出來了,我自己又新增了一些小改動,本以為也是可行的,結果卻發現了乙個問題,關於0、null與『\0』的關係問題。

先將正確解題**奉上。

```

#include using namespace std;

// length: n位數

// number: n+1位的陣列(字串)

// numberindex: 高位的位數在number中的下標值

void print1tomax(int length, char* number, int numberindex)

/* // char* number = new char[length + 1];後建立的是null陣列 null=='\0'不能用來判斷

if(number[numberindex + 1] == '\0') */

// 低位的迴圈結束後返回高位的迴圈 高位i++後繼續進入低位 再次開啟迴圈

for(int i = 0; i < 10; i++) }

int main()

delete number;

return 0;

}```

不考慮大數

```#include #include "math.h"

using namespace std;

int main()

limitnum--;

/*--n;

while(n >= 0)*/

cout << limitnum << endl;

int num = 1;

while(num <= limitnum)

return 0;

}```

C 學習中遇到的問題

在c 學習中遇到的問題集中在此,若有高人看見希望給出解決辦法,在日後的學習中本人若找到解決辦法,也在此更新!1 如何實現ipconfig all命令的全部功能 region 另類解法 程式如下 system.diagnostics.process p new system.diagnostics.p...

求助 C 程式設計中遇到的問題

自己寫了一段 windows窗體應用程式 主要用於實現風車的轉動,但出現了一點問題,求助。using system using system.collections.generic using system.componentmodel using system.data using system....

C 學習過程中遇到的問題

string sqlcmd1 select table name from user tables where table name like tablename oracleparameter op new oracleparameter tablename this.loadkey.text.t...