14.C++读入一系列整数,统计出正整数个数i和负整数个数j,读入0则结束
代码://2_9.cpp//读入一系列整数,统计出正整数个数i和负整数个数j,读入0则结束#include <iostream>using namespace std;int main() {int i = 0, j = 0, n;cout << "Please enter some integers(enter 0 to quit):" << endl;cin
·
代码:
//2_9.cpp
//读入一系列整数,统计出正整数个数i和负整数个数j,读入0则结束
#include <iostream>
using namespace std;
int main() {
int i = 0, j = 0, n;
cout << "Please enter some integers(enter 0 to quit):" << endl;
cin >> n;
while (n != 0) {
if (n > 0) i++;
if (n < 0)j++;
cin >> n;
}
cout << "Count of positive integers :" << i << endl;
cout << "Count of negetive integers :" << j << endl;
return 0;
}
运行结果:

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)