此程序接受整数并按升序对其进行排序。我的问题是它不输出用逗号分隔的数字,有人可以帮我这个吗?
#include <iostream>
#include <cstdlib>
using namespace std;
int main () { int x;
int array [10], t;
for (x=0; x<10; x++)
{
cout << "Enter integer number: " << endl;
cin >> array[x];
}
for (x=0; x<10; x++)
{
for (int y=0; y<9; y++)
{
if(array[y]>array[y+1])
{
t=array[y];
array[y]=array[y+1];
array[y+1]=t;
}
}
}
cout << "The integers in ascending order are : ";
for (x=0;x<10;x++)
{
cout <<"\n";
cout <<array[x];
cout << "\n";
}
system ("pause");
return 0;
}
答案 0 :(得分:0)
只需打印逗号而不是新行
for (x=0;x<10;x++)
{
cout <<array[x]<<",";
}
答案 1 :(得分:0)
按如下方式更正组的最后一个:
for (x=0;x<10;x++)
{
cout <<array[x];
cout << ",";
}
答案 2 :(得分:0)
cout << "The integers in ascending order are : ";
for (x=0;x<10;x++)
{
cout <<array[x];
cout << ","; ---> changed this line and it prints output with commas
}
谢谢大家帮助我,我很感激:)