Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
菜鸟求助:大家帮我看看代码怎么错了#include <iostream> #include <cmath> using namespace std; //double result[1000]; int main() { double n, p, k, temp; int i, counter = 0; double* result; while(cin >> n >> p) { result = new double; k = 2; temp = pow(k, n); while(temp < p) { k++; temp = pow(k, n); } if (temp == p) { result[counter++] = k; } else if (temp > p) { result[counter++] = k - 1; } } i = 0; while(i < counter) { printf("%.0lf\n", result[i++]); } return 0; } 为啥只有最后一个结果是对的?? 而如果我用静态数组 就对了 是不是我动态数组哪写错了?? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator