|
|
back to boardDiscussion of Problem 1068. SumWhats problem? C++ #include <iostream> using namespace std; int main() { int n,res=0; cin >> n; if (n < 0) { n = n*-1; int *arr; arr = new int[n+2]; arr[0] = 1; for (int i = 1; i < n+2; i++) { arr[i] = arr[i - 1] - 1; } for (int i = 0; i < n+2; i++) { res = res + arr[i]; } cout << res; } else if(){ int *arr; arr = new int[n]; arr[0] = 1; for (int i = 1; i < n; i++) { arr[i] = arr[i - 1] + 1; } for (int i = 0; i < n; i++) { res = res + arr[i]; } cout << res; } return 0; } Re: Whats problem? C++ Posted by German 21 Oct 2016 19:00 n = n*-1; ? arr[i] = arr[i - 1] - 1; ? -10000.....-1 0 1 |
|
|