桐子


私信TA

用户名:uq_57082150845

访问量:2121

签 名:

等  级
排  名 12653
经  验 910
参赛次数 0
文章发表 6
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:


#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<string.h>

void strshot(char * str[]) //冒泡法排序字符串   //本题无用

{

for(int i=0;i<3;i++)

{

char * s= str[i];

for(int j=0;j<strlen(s)-1;j++)

{

for(int k=0;k<strlen(s)-1-j;k++)

{

if(s[k]>s[k+1])

{

char t=s[k];

s[k]=s[k+1];

s[k+1]=t;

}

}

}

}

}

void  strshot2(char * str[]) // 字符数组排序 

{

for(int i=0;i<2;i++)

{

for(int j=0;j<2-i;j++)

{

if(strcmp(str[j],str[j+1])>0)

{

char * temp=(char *)malloc(sizeof(char)*100);

strcpy(temp,str[j]),strcpy(str[j],str[j+1]),strcpy(str[j+1],temp);

}

}

}

}

int main()

{

char * str[3]; //定义 指针数组 

for(int i=0;i<3;i++) 

{

str[i]=(char *)malloc(sizeof(char)*100);  //定义字符串 

gets(str[i]); 

}

strshot2(str);

for(int i=0;i<3;i++)

{

puts(str[i]);

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区