2009年9月全国计算机等级考试二级C语言程序设计题(79)
来源:优易学  2011-7-30 16:54:37   【优易学:中国教育考试门户网】   资料下载   IT书店
题目:字符串排序。
  1.程序分析:
  2.程序源代码:
  main()
  {
  char *str1[20],*str2[20],*str3[20];
  char swap();
  printf("please input three strings\n");
  scanf("%s",str1);
  scanf("%s",str2);
  scanf("%s",str3);
  if(strcmp(str1,str2)>0) swap(str1,str2);
  if(strcmp(str1,str3)>0) swap(str1,str3);
  if(strcmp(str2,str3)>0) swap(str2,str3);
  printf("after being sorted\n");
  printf("%s\n%s\n%s\n",str1,str2,str3);
  }
  char swap(p1,p2)
  char *p1,*p2;
  {
  char *p[20];
  strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
  }

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训