#include<stdio.h> #include<string.h> #define N 4 #define LEN 20 void main() { int i,j; char temp[LEN], name[N][LEN] = {"China","America","Austlia","Japan"}; for(i=1;i<=N;i++) for(j=0;j<N-i;j++) if(strcmp(name[j],name[j+1])>0) { strcpy(temp,name[j]); strcpy(name[j],name[j+1]); strcpy(name[j+1],temp); } for(i=0;i<N;i++) printf("%s\n",name[i]); }
#include<stdio.h> #include<string.h> #define N 4 void main() { int i,j; char *temp, *name[N] = {"China","America","Austlia","Japan"}; for(i=1;i<=N;i++) for(j=0;j<N-i;j++) if(strcmp(name[j],name[j+1])>0) { temp = name[j]; name[j] = name [j+1]; name[j+1] = temp; } for(i=0;i<N;i++) printf("%s\n",name[i]); }
时间: 2024-10-11 03:53:12