English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

題目是在字元陣列放入未按順序排列的26個英文字母,
然後字母依 a~z 順序從螢幕輸出。

下面是我打的程式 但是不知道錯在哪

#include
#include
#define n 80
#include
using namespace std;
void sort (char [][n],int);

int main()
{
char str[][n] = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
sort(str,26);
for (int i=0;i<26;i++)
cout< }
void sort (char [][n],int count)
{
char temp[n]
for(int i=0;i for(int j=i+1;j if(strcmp(str[i],str[j])>0){
strcpy(temp,str[j]);
strcpy(str[j],str[i]);
strcpy(str[i],temp);
}
system("pause");
}

2006-11-26 13:33:02 · 2 個解答 · 發問者 2 in 電腦與網際網路 程式設計

2 個解答

char str[][n] = ("a","b","c"," ....... ,"w","x","y","z"); //不是這樣寫
char str[][n] = { "a","b","c"," ....... ,"w","x","y","z" }; // 要用 { } 才對

char temp[n] ; // 少了 ;

還有你的 system("pause"); 放的位置怪怪的.. 你這樣放會在排序裡面暫停,按任何鍵回去後才列出結果..如果你沒有自己開一個 console mode , 會什麼都沒看到就關掉了

// 雖然結果會是你要的樣子..不過建議不要這樣子寫比較好

2006-11-26 13:54:21 · answer #1 · answered by 鳳琳 5 · 0 0

//Power by Microsoft Visual Studio 2005//可以使用 Dev-C++ 編譯此程式#include#include#define LENGTH 27using namespace std;int main(int argc,char **argv){ //=====START=====// void resort(int LEN,char *CHAR); int i; char CHAR='Z',letter[LENGTH]; for(i=0;i*(CHAR+j)){    temp=*(CHAR+i);    *(CHAR+i)=*(CHAR+j);    *(CHAR+j)=temp;   }  } }}//泡沫浮昇排序法

2006-11-26 14:04:50 · answer #2 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers