一个只显示负数的程序
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");
Go to Project > Properties > Linker > System > SubSystem > then from the dropdown menu choose > Console (/SUBSYSTEM:CONSOLE)
#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;
}
我需要编写一个程序,只显示给定向量中的负数。我做到了,但没有用。有人可以告诉我为什么这段代码不起作用吗?
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");
Go to Project > Properties > Linker > System > SubSystem > then from the dropdown menu choose > Console (/SUBSYSTEM:CONSOLE)
#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;
}