Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- void bubble(int*,int);
- int main(void){
- int data[5],i,j;
- printf("請輸入5個數字:");
- for(i=0;i<5;i++){
- scanf("%d",&data[i]);
- }
- bubble(data,5);
- printf("排序好的陣列:");
- for(j=0;j<5;j++){
- printf("%d ",data[j]);
- }
- }
- void bubble(int data[],int count){
- int i,j,temp;
- for(i=count;i>1;i--){
- for(j=0;j<i-1;j++){
- if(data[j+1]>data[j]){
- temp=data[j+1];
- data[j+1]=data[j];
- data[j]=temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement