pack((i + 1),& MO); Amult(& N1,& MO,& N1); printf(" \ nPogress:%d",i); i ++; } if(ff!= NULL){ fprintf(ff," \ n%d \ n",i + 1); AEIfprintf(ff,& N1); } fclose(ff); printf(" \\ \\ n进展:100%"); 返回0; } void AEIprintf(struct AEI * N1){ double fieldLength; double temp ; char format0 [8]; char format1 [8]; long j; j = N1 - > digits-1; fieldLength = log10(base); temp = modf(fieldLength,& fieldLength); format0 [0] =''%''; format0 [1] = fieldLength + 48; format0 [2] =''d''; format0 [3] = 0x00; format1 [0] =''%''; format1 [1] =''0 ''; format1 [2] = fieldLength + 48; format1 [3] =''d''; format1 [4 ] = 0x00; printf(format0,N1-> data [j]); j--; while(j> = 0) { printf(format1,N1-> data [j]); j--; } 返回; } 无效AEIfprintf(FILE * fp,struct AEI * N1){ long j = N1-> digits-1; double fieldLength,temp; char format0 [8],format1 [8]; fieldLength = log10(base); temp = modf(fieldLength,& fieldLength); format0 [0] =''%''; format0 [1] = fieldLength + 48; format0 [2] =''d''; format0 [3] = 0x00; format1 [0] =''%''; format1 [1] =''0''; format1 [2] = fieldLength + 48; format1 [3] =''d''; format1 [4] = 0x00; fprintf(fp,format0, N1-> data [j]); j--; while(j> = 0){ fprintf(fp,format1,N1-> data [j]); j--; } return; } void pack(IntegerArrayType i,struct AEI * N1) { long t = 1,i1,j = 0; 而(t == 1){ i1 = i%base; N1-> data [j] = i1; i =(i - i1)/ base; j ++; if(i == 0) t = 0; } N1-> digits = j; 返回; } void Aadd(struct AEI * A,struct AEI * B,struct AEI * C){/ * C = A + B * / long carry = 0,result,i = 0,d; if(A-> digits> B->数字){ d = A->数字; }否则{ d = B->数字; } while(i< d&& i< al){ result = A-> data [i] + B-> data [i] + carry; C-> data [i ] =结果%base; carry =(结果 - 结果%基数)/ base; i ++; } if(carry!= 0&& i< al){ C-> data [i] = carry; d ++; } if(i == al){ printf(" \\\Aadd Array overflow"); } C-> digits = d; 返回; } void Ambi(struct AEI * A,IntegerArrayType B,struct AEI * C){ / * C = A * B; B是整数; * / long carry = 0,结果,i = 0,d; d = A->数字; while(i< d){ result = A-> data [i] * B + carry; C-> data [i ] =结果%base; carry =(结果 - 结果%基数)/ base; i ++; } if(carry!= 0&& i< al){ C-> data [i] = carry; d ++; } if(i == al){ printf(" \\\Ambi Array overflow"); } C-> digits = d; 返回; } void Lshift (struct AEI * A,IntegerArrayType B,struct AEI * C){ / * C = A LS B; B是整数; * / long i = 0; while(i< A-> digits&&(i + B)< al){ C-> data [i + B] = A-> data [i]; i ++; } if(i + B == al){ printf(" \\\Array overflow"); } C->数字= A->数字+ B; 返回; } void Amult(struct AEI * A,struct AEI * B,struct AEI * C){ / * C = A * B; * / 长i,ii; struct AEI Temp,Temp1,ANS; ii = 0 ; while(ii< al){ ANS.data [ii] = 0; ii ++; } ANS.digits = 0; i = 0; while(i< B-> digits){ ii = 0; 而(ii< al){ Temp1.data [ii] = 0; Temp.data [ii] = 0; ii ++; } Temp.digits = 0; Temp1.digits = 0; Lshift(A,i,& Temp); if(B-> data [i]!= 0){ Ambi(& Temp,B-> data [i],& Temp1); Aadd(& Temp1,& ANS,& ; ANS); } i ++; } i = 0; while(i< al){ C-> data [i] = ANS.data [i]; i ++; } C-> digits = ANS.digits; 返回; } =========================结束粘贴=============== ============== 先谢谢。I wrote a program to calculate factorials of large numbers. The longprecission integers are stores in arrays. When i specify the length ofthese arrays larger than 16000 elements, each element is a long int,the windows refuses to execute the program. More precicely the codeterminates as soon as it starts to execute. How can i overcome thisissue. Note, if array length is set smaller the code runs with noproblems.Here is the code:==========================Start Paste==========================#include<stdio.h>#include<stdlib.h>#include<math.h>#define al 8024*8#define base 1000typedef long int IntegerArrayType;struct AEI{IntegerArrayType data[al];long int digits;};void pack(IntegerArrayType i, struct AEI *N1);void Aadd(struct AEI * A, struct AEI * B, struct AEI * C);void Ambi(struct AEI * A, IntegerArrayType B, struct AEI * C);void Lshift(struct AEI * A, IntegerArrayType B, struct AEI * C);void Amult(struct AEI * A, struct AEI * B, struct AEI * C);void AEIprintf(struct AEI * N1);void AEIfprintf(FILE * fp, struct AEI * N1);int main(void){struct AEI N1, MO;long i = 0, j = 0, ii, NUM;FILE *ff;while (i < al){N1.data[i] = 0;MO.data[i] = 0;i++;}printf("Enter integer to Factorialize: ");scanf("%ld", &NUM);pack(1, &N1);ff = fopen("Results.txt", "w");printf("you entered: %ld", NUM);i=1;while(i < NUM ){ii = 1;while (ii < al){MO.data[ii] = 0;ii++;}pack((i+1), &MO);Amult(&N1, &MO, &N1);printf("\nPogress: %d", i);i++;}if(ff!=NULL){fprintf(ff,"\n%d\n",i+1);AEIfprintf(ff, &N1);}fclose(ff);printf("\nPogress: 100%");return 0;}void AEIprintf(struct AEI *N1){double fieldLength;double temp;char format0[8];char format1[8];long j;j = N1->digits-1;fieldLength = log10(base);temp = modf(fieldLength, &fieldLength);format0[0] = ''%'';format0[1] = fieldLength + 48;format0[2] = ''d'';format0[3] = 0x00;format1[0] = ''%'';format1[1] = ''0'';format1[2] = fieldLength + 48;format1[3] = ''d'';format1[4] = 0x00;printf(format0, N1->data[j]);j--;while (j >= 0){printf(format1, N1->data[j]);j--;}return;}void AEIfprintf(FILE * fp, struct AEI *N1){long j = N1->digits-1;double fieldLength, temp;char format0[8], format1[8];fieldLength = log10(base);temp = modf(fieldLength, &fieldLength);format0[0] = ''%'';format0[1] = fieldLength + 48;format0[2] = ''d'';format0[3] = 0x00;format1[0] = ''%'';format1[1] = ''0'';format1[2] = fieldLength + 48;format1[3] = ''d'';format1[4] = 0x00;fprintf(fp,format0, N1->data[j]);j--;while (j >= 0){fprintf(fp, format1, N1->data[j]);j--;}return;}void pack(IntegerArrayType i, struct AEI * N1){long t = 1, i1, j = 0;while (t == 1){i1 = i % base;N1->data[j] = i1;i = (i - i1) / base;j++;if (i == 0)t = 0;}N1->digits=j;return;}void Aadd(struct AEI *A, struct AEI *B, struct AEI *C){ /* C = A + B*/long carry = 0, result, i =0, d;if(A->digits>B->digits){d=A->digits;}else{d=B->digits;}while (i < d && i<al){result = A->data[i] + B->data[i] + carry;C->data[i] = result % base;carry = (result - result % base) / base;i++;}if(carry!=0 && i<al){C->data[i]=carry;d++;}if(i==al){printf("\nAadd Array overflow");}C->digits=d;return;}void Ambi(struct AEI *A, IntegerArrayType B, struct AEI *C){/*C = A * B; B is integer; */long carry = 0, result, i = 0, d;d=A->digits;while (i < d){result = A->data[i] * B + carry;C->data[i] = result % base;carry = (result - result % base) / base;i++;}if(carry!=0 && i<al){C->data[i]=carry;d++;}if(i==al){printf("\nAmbi Array overflow");}C->digits=d;return;}void Lshift(struct AEI * A, IntegerArrayType B, struct AEI * C){/*C = A LS B; B is integer; */long i = 0;while (i<A->digits && (i + B) < al){C->data[i + B] = A->data[i];i++;}if(i+B==al){printf("\nArray overflow");}C->digits=A->digits+B;return;}void Amult(struct AEI * A, struct AEI * B, struct AEI * C){/*C = A * B; */long i, ii;struct AEI Temp, Temp1, ANS;ii = 0;while (ii < al){ANS.data[ii] = 0;ii++;}ANS.digits=0;i = 0;while (i < B->digits){ii = 0;while (ii < al){Temp1.data[ii] = 0;Temp.data[ii] = 0;ii++;}Temp.digits=0;Temp1.digits=0;Lshift(A, i, &Temp);if(B->data[i]!=0){Ambi(&Temp, B->data[i], &Temp1);Aadd(&Temp1, &ANS, &ANS);}i++;}i = 0;while(i<al){C->data[i]=ANS.data[i];i++;}C->digits=ANS.digits;return;}=========================End Paste=============================thanks ahead.推荐答案顺便说一下,我用的是带有AMD Athlon64 3200 CPU的emachine M6810笔记本 和512 MB的ram 。当我执行代码时,我有大约300MB的免费 ram。By the way i am on emachine M6810 notebook with AMD Athlon64 3200 CPUand 512 MB of ram. when i execute the code i have about 300MB of freeram. fermineutron写道:fermineutron wrote: 顺便说一下,我使用AMD Athlon64 3200 CPU的emachine M6810笔记本 和512 MB内存。当我执行代码时,我有大约300MB的免费 ram。By the way i am on emachine M6810 notebook with AMD Athlon64 3200 CPUand 512 MB of ram. when i execute the code i have about 300MB of freeram. 使用lcc-win32你的程序没有任何问题。 http://www.cs.virginia.edu / ~lcc-win32你的问题与C标准AFAIK无关。 但是对于未来的参考,任何出现在两个功率附近的问题(我怀疑它失败的实际位置接近16,384)很可能与某些限制相关的b $ b ,如每个局部变量的限制为32,767或65,536字节。 尝试使用32位编译器编译程序,我怀疑 问题将消失,(或至少推迟到32位限制)。your problem as nothing to do with the C standard AFAIK.But for future reference, any problem that shows up near a power of two(I suspect the actual place it fails is nearer to 16,384) is likely tobe related to some limit, like a limit of 32,767 or 65,536 bytes perlocal variable.Try compiling your program with a 32-bit compiler and I suspect theproblem will go away, (or at least be postponed until the 32-bit limit). 这篇关于C exe对winXP内存的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 12:28