仅显示负数的程序
A program that will show only negative numbers
我需要编写一个程序,该程序将仅显示给定向量的负数。我做到了,但它不起作用。有人可以告诉我为什么这段代码不起作用吗?
int main(int argc, char *argv[])
{
int const m = 6;
int A[m] = { 1, -2, 3, -4, 5, -6 };
int i;
std::cout << "A[negative]={";
for (i = 0; i < m; i++)
if (A[i] < 0)
std::cout << A[i];
std::cout << "}" << std::endl;`
system("PAUSE");
return EXIT_SUCCESS;
}
程序运行良好 我只添加了#include <iostream>
并将 return 语句更改为以下return 0;
我不知道你用的是什么IDE,但如果你使用的是Visual Studio。最好执行以下操作,而不是使用system("PAUSE");
转到"项目>属性">链接器>系统>子系统>,然后从下拉菜单中选择">控制台"(/子系统:控制台)
#include <iostream>
int main(int argc, char *argv[])
{
int const m = 6;
int A[m] = { 1, -2, 3, -4, 5, -6 };
int i;
std::cout << "A[negative]={";
for (i = 0; i < m; i++)
if (A[i] < 0)
std::cout << A[i];
std::cout << "}" << std::endl;
return 0;
}
相关文章:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 程序显示以退出代码 0; 结束
- 为什么此程序显示"unreachable code"警告?我该如何抑制它?
- 为什么程序显示我"was not declared in this scope"?
- 我的程序显示许多错误,"error: no matching function for call to 'getPercentScore'"
- 将数据分配给了数组分配,但程序显示了以缓冲区超支的输出
- 为什么程序显示的值大于结果或垃圾值
- 为什么程序显示字符串超出范围
- 有人可以解释为什么该程序显示我 6 和 4
- 我的QT程序显示带有标题的空白窗口
- C 如何使我的程序显示值而不是内存位置
- 使QT/C 程序显示其文件类型,如Windows上已知
- 如何在所有平台上使用C++程序显示重音字符
- 更新:程序显示fstream的地址,而不是文本文件
- 程序显示学生的详细信息,如名字父亲名字滚动没有CGPA输出
- Google Drive将我的应用程序显示为病毒
- 我的程序显示空的表面,它需要在那里显示地图
- 凭据提供程序.显示一种进度条并禁用密码或PIN字段
- 无法让我的C++程序显示输出
- c++程序显示投票的百分比不显示正确的结果