[問題] 不知道問題出在哪

看板C_and_CPP (C/C++)作者 (想念物理的資工人)時間16年前 (2009/08/23 14:46), 編輯推噓2(200)
留言2則, 1人參與, 最新討論串2/3 (看更多)
#include <iostream> using namespace std; #define max 4294967295 void set(int , int *); int * multi_hight(int , int *); int * add(int *op1, int *op2); int main(){ unsigned int a, b; cin >> a; cin >> b; if(a <= max && b <= max){ int c = max; int op1[25]; int op2[25]; for(int i = 0; i < 25; i++) { op1[i] = -1; op2[i] = -1; } set(c, op1); set(b, op2); /* for(int j = 0; op1[j] != -1 || op2[j] != -1; j++){ if(op1[j] != -1)cout << op1[j] ; if(op2[j] != -1)cout << op2[j] ; } */ for(int i = 0; add(multi_hight(a, op1), op2)[i]>=0; i++) cout << add(multi_hight(a, op1), op2)[i]; } cout << endl; system("pause"); return 0; } void set(int n, int *array){ int index = 0; while(n != 0){ array[index++] = n%10; n /= 10; } } int * multi_hight(int n, int *array){ int t[25]; for(int k = 0; k < 25; k++){ t[k] = array[k]; } while(n > 0){ int *t = add(array, t); n--; } return t; } int * add(int *op1, int *op2){ int carry = 0, i = 0, f = 0; int temp[25]; while(op1[i] >= 0 && op2[i] >= 0){ if((f = op1[i]+op2[i]+carry)>=10){ temp[i] = f%10; carry = 1; } else { temp[i] = f; carry = 0; } i++; } while(op1[i]>=0 && i < 25) { temp[i] = op1[i]; i++; } while(op2[i]>=0 && i < 25) { temp[i] = op2[i]; i++; } return temp; } 這是要做一個64bits加法的問題 我compile有過但是run完有問題 程式經驗不足 找不出問題 ><" 煩請各位先進不吝次教~ 感謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.218.120

08/23 20:20, , 1F
十戒#6 in function "multi_hight"
08/23 20:20, 1F

08/23 20:23, , 2F
還有#3 一樣在multi_hight
08/23 20:23, 2F
文章代碼(AID): #1AaENNt0 (C_and_CPP)
文章代碼(AID): #1AaENNt0 (C_and_CPP)