[問題] 十進位轉二進位
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
這是我寫的一個十進位轉二進位的程式,小的數字都還ok正常但是只要輸入一個
超大的數執行完通常都沒有結果,我覺得是不是因為陣列的容量太小?
有沒有辦法可以解決
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<iostream>
#include<cstdlib>
using namespace std;
void tentotwo(int,int[]);
void tentotwo(int num,int matrix[]){
int i,count;
count=0;
while(num>=1){
matrix[count]=num%2;
num=num/2;
count++;
}
count--;
for(i=count;i>=0;i--){
cout<<matrix[i]<<"";
}
}
int main(void){
int num;
int *matrix=new int[5000000];
cout<<"輸入一個數字"<<endl;
cin>>num;
tentotwo(num,matrix);
system("pause");
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.204.250.31
推
03/09 22:04, , 1F
03/09 22:04, 1F
我輸入1000000000都還OK在多一點就不行
※ 編輯: wuwu66 來自: 123.204.250.31 (03/09 22:07)
→
03/09 22:18, , 2F
03/09 22:18, 2F
推
03/09 22:18, , 3F
03/09 22:18, 3F
29
※ 編輯: wuwu66 來自: 123.204.250.31 (03/09 22:23)
→
03/09 22:57, , 4F
03/09 22:57, 4F
→
03/09 23:00, , 5F
03/09 23:00, 5F
→
03/09 23:03, , 6F
03/09 23:03, 6F
推
03/09 23:52, , 7F
03/09 23:52, 7F
推
03/10 01:01, , 8F
03/10 01:01, 8F
→
03/14 18:39, , 9F
03/14 18:39, 9F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章