【发布时间】:2015-01-26 10:19:31
【问题描述】:
我想创建一个最合适的内存分配解决方案。
int main()
{
int input;
int memoryBlock[ARRAY_SIZE] = {5, 10, 3, 9, 7};
int bestFit;
cout << "Please enter the memory size you want to allocate: ";
cin >> input;
for (int i = 0; i < ARRAY_SIZE; i++){
if (memoryBlock[i] - input < 0 ){
}
else {
bestFit = memoryBlock[i];
}
}
cout << bestFit;
}
基于上面的代码,我如何修改它以使else {} 选择最接近它的数字?
提前致谢。
【问题讨论】:
标签: c++ memory allocation