65,211
社区成员
发帖
与我相关
我的任务
分享#include<stdio.h>
void paixu(char str[10])
{
int i,j,t;
for(j=0;j<10;j++)
for(i=0;i<9-j;i++)
if(str[i]>str[i+1])
{
t=str[i];
str[i]=str[i+1];
str[i+1]=t;
}
}
void main()
{
char str[10];
int i;
gets(str);
paixu(str);
for(i=0;i<10;i++)
printf("%c",str[i]);
printf("\n");
}
//改了个。
#include <iostream>
using namespace std;
void maopao(int list[],int n);
void maopao(int list[],int n)
{
int exchange,i,j,temp;
for(int i=0;i <n;i++)
{
exchange=0;
for(int j=0;j<n-i;j++) ///////////
//{
if(list[j+1] <list[j])
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
exchange=1;
}
//}
}
}
// if(exchange=1)
// return ;
int main()
{ const char blank=' ';
const int n=10;
int list[n]={1,3,5,7,9,2,4,6,10,0};
maopao(list,10);
for(int i=0;i <n;i++)
{
cout <<list[i] <<blank;
if((i+1)%10==0) cout <<endl;
}
cout <<endl;
system("pause");
return 0;
}
#include <iostream>
using namespace std;
void maopao(int list[],int n)
{
int exchange,i,j,temp;
for(i=0;i <n;i++) //////////改
{ //////////改
exchange=0;
for(j=n-1;j>i;j--) //////////改
{
if(list[j] <list[j-1]) //////////改
{
temp=list[j-1];
list[j-1]=list[j];
list[j]=temp; //////////改
exchange=1;
}
}
}
}
// if(exchange=1)
// return ;
int main()
{ const char blank=' ';
const int n=10;
int list[n]={1,3,5,7,9,2,4,6,10,0};
maopao(list,n); //////////改
for(int i=0;i <n;i++)
{
cout<<list[i]<<blank;
if((i+1)%10==0) cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}