本帖最后由 supergcs 于 2014-11-12 20:09 编辑
- /*
- 输入六个字符串,比较字符串大小并且由小到大排序
- */
- #import <Foundation/Foundation.h>
- #import <stdio.h>
- int main(){
- char *strArray[6];
-
- for (int i = 0; i < 6; i++) {
- printf("请输入第%d个字符串\n",i+1);
-
- scanf("%s",strArray[i]);
- }
-
- for (int i = 0; i < 5; i++) {
- for (int j = i+1; j < 6; j++) {
- if (strcasecmp(strArray[i], strArray[j]) > 0) {
- char *temp;
-
- temp = strArray[i];
-
- strArray[i] = strArray[j];
-
- strArray[j] = temp;
- }
- }
- }
- printf("排序结果为:\n");
- for (int i = 0; i < 6; i++) {
- printf("%s\n",strArray[i]);
- }
- return 0;
- }
复制代码
|