|  | 
|  | 
| вернуться в форум | wrong answer C++ Послано Igor  20 мар 2023 12:40I want to solve the problem using a dynamic array. But the compiler outputs this: HEAP CORRUPTION DETECTED: after Normal block (#150) at 0x000001EEFBCDB420.CRT detected that the application wronte to memory after end of heap buffer.
 
 #include <iostream>
 #include <cmath>
 #include <iomanip>
 using namespace std;
 void main()
 {
 int size = 0, i = 0;
 int* a = new int[size];
 unsigned int x;
 while (cin >> x)
 {
 size += 1;
 for (; i < size;++i)
 {
 a[i] = x;
 
 }
 
 }
 
 for (int i = size-1; i >= 0; --i)
 {
 cout << fixed << setprecision(4) << sqrt(a[i]) << endl;
 }
 delete[] a;
 
 Edited by author 20.03.2023 12:40
Re: wrong answer C++ Послано vzhanm  29 апр 2024 11:23Type int will overflow. Use unsigned long long instead. | 
 | 
|