/*Bubbling Program*/
#include<stdio.h>
#define N 5//Defining the arrys N is five//
int main() {
int arrys[N],i,j,temp;
for(i=0; i<N; i++) {
scanf("%d",&arrys[i]);
}
for(i=0; i<N; i++) {
for(j=0; j<N-1-i; j++) { //Many students can write j<N-i,in fact ,which is rong.Thinking why?//
if(arrys[j]>arrys[j+1]) {//Changing the number//
temp=arrys[j];
arrys[j]=arrys[j+1];
arrys[j+1]=temp;
}
}
}
//ergodic and output format//
for(i=0; i<N; i++)
printf("%4d",arrys[i]);
return 0;
}![在这里插入图片描述](https://img-blog.csdnimg.cn/2020022410424226.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTcxMzM1Mg==,size_16,color_FFFFFF,t_70)
C语言-数组编写冒泡程序
猜你喜欢
转载自blog.csdn.net/weixin_45713352/article/details/104473346
今日推荐
周排行