|
|
back to boardAnyone can shed some light for me[wrong answer:( ] =========================== #include <stdio.h> #include <math.h> #include <iostream> #define MAXNUM 32768 using namespace std; void main() { int i = 0; double dList[MAXNUM]; double dCur = 0.0;
while(cin>>dCur) { if(dCur >=0.0 ) { dList[i] = sqrt(dCur); ++i; } if(i>= MAXNUM) break; }
while(i>0) { printf("\n%.4f", dList[i-1]); --i; } } ============================== Re: Anyone can shed some light for me[wrong answer:( ] well, the original problem was resolved. I used malloc to allocate larger array instead of using static array. Here is a new question, why do I get "compilation error" through the code below?(both via c or c++ type) >>>>>>>>>>>>>>>>>>>>>>>> #include <stdio.h> #include <math.h> #include <malloc.h> #define MAXNUM 800000 void main() { int i = 0; double *dList = NULL; double dCur = 0.0; dList = (double*)malloc(MAXNUM * sizeof(double));
while(scanf("%lf", &dCur) != EOF) { if(dCur >=0.0 ) { dList[i] = sqrt(dCur); ++i; }
}
while(i>0) { printf("%.4f\n", dList[i-1]); --i; } free(dList); } <<<<<<<<<<<<<<< Re: Anyone can shed some light for me[wrong answer:( ] Posted by Une 9 Oct 2007 06:39 Edited by author 09.10.2007 06:41 |
|
|