#include
int main()
{
int arraysize,t,j;
int *array;
cout<<"please input a number of array elements:\n";
cin>>arraysize;
if((array=new int[arraysize])==NULL)
{
cout<<"can't allocate more memory,terminating.\n";
exit(1);
}
for(int count=0;count
array[count]=count+100;
for(int i=0;i
{
for(int j=0;j
{
if(array[j]>array[j+1])
{
t=array[j];
array[j]=array[j+1];
array[j+1]=t;
}
}
}
cout<<array[j]<<" "<<endl;
delete[]array;
return 0;
}
要求在堆空间分配5个整型变量空间,分别存放100,200,300,400,500,要求把这个五个数倒序输出,即输出500,400,300,200,100。(要求使用new和delete操作符分配和回收堆空间)下面程序错那了?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2019-09-15 20:37关注
for(int count=0;count array[count]=count+100;
for(int i=0;i {
for(int j=0;j {
这里都不对完整给你写一个
#include <iostream> using namespace std; int main() { int n; cin >> n; int * arr = new int[n]; if (!arr) { cout << "error on alloc"; return; } for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = n - 1; i >= 0; i--) cout << arr[i] << " "; delete[] arr; return 0; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 运筹学排序问题中的在线排序
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
- ¥30 求一段fortran代码用IVF编译运行的结果
- ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
- ¥15 C++ 头文件/宏冲突问题解决
- ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
- ¥50 安卓adb backup备份子用户应用数据失败
- ¥20 有人能用聚类分析帮我分析一下文本内容嘛
- ¥30 python代码,帮调试,帮帮忙吧