/*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;
}
C语言-数组编写冒泡程序
猜你喜欢
转载自blog.csdn.net/weixin_45713352/article/details/104473346
今日推荐
周排行