C++编程题
用new运算符为一个包含20个整数的数组分配内存,输入若干个值到数组,分别统计其中正数与负数的个数,输出结果,再用delete运算符释放动态内存空间
C++编程题 用new运算符为一个包含20个整数的数组分配内存,输入若干个值到数组,分别统计其中
答案:1 悬赏:0
解决时间 2021-03-06 04:58
- 提问者网友:朱砂泪
- 2021-03-05 07:15
最佳答案
- 二级知识专家网友:开心就好
- 2021-03-05 08:33
#include
#include
using namespace std;
int main()
{
int *p = new int[20];
int i = 0;
while (cin >> p[i])
++i;
cout << count_if(&p[0], &p[i], [](int n){return 0 < n; }) << endl;
cout << count_if(&p[0], &p[i], [](int n){return n < 0; }) << endl;
delete []p;
return 0;
}
#include
using namespace std;
int main()
{
int *p = new int[20];
int i = 0;
while (cin >> p[i])
++i;
cout << count_if(&p[0], &p[i], [](int n){return 0 < n; }) << endl;
cout << count_if(&p[0], &p[i], [](int n){return n < 0; }) << endl;
delete []p;
return 0;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯