2017-02-07 24 views
0

該程序採用整數並按升序對它們進行排序。我的問題在這裏是不輸出數字用逗號分隔,有人可以幫我這個嗎?輸出整數以逗號分隔的C++程序

#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

只是打印逗號而不是新的行

for (x=0;x<10;x++) 
     { 
      cout <<array[x]<<","; 
     } 
+0

cout <<「整數順序是:「; (x = 0; x <10; x ++) cout <<「,」; } – AmoghN

+1

我做了這些改變,它的工作,謝謝:) – AmoghN

+0

很高興它幫助! –

0

糾正持續組分別如下:

for (x=0;x<10;x++) 
{ 
    cout <<array[x]; 
    cout << ",";  
} 
+0

cout <<「整數升序爲:」; (x = 0; x <10; x ++) cout <<「,」; } – AmoghN

+1

我做了這些改變,它的工作,謝謝:) – AmoghN

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 
    } 

謝謝大家對我的幫助,我很感激: )