输入五个国家的名称按字母顺序排列输出。
#define _CRT_SECURE_NO_WARNINGS \Microssoft Visual Studio非搞得跟别人不一样 #include#include int main() { char country_name[5][20], temp[20]; int i, j, p; printf("input country's name:n"); for (i = 0; i < 5; i++) { gets(country_name[i]); } printf("n"); for (i = 0; i < 5; i++) { p = i; strcpy(temp, country_name[i]); for (j = i + 1; j < 5; j++) { if (strcmp(country_name[j], temp) < 0) { p = j; strcpy(temp, country_name[j]); } } if (p != i) { strcpy(temp, country_name[i]); strcpy(country_name[i], country_name[p]); strcpy(country_name[p], temp); } puts(country_name[i]); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)