#include<stdio.h>
#include<string.h>
//冒泡排序
void bubb(int arr[],int len)
{for(int i=1;i<len;i++){for(int j=0;j<len-i+1;j++){if(arr[j+1]<arr[j]){int t=arr[j];arr[j]=arr[j+1];arr[j+1]=t;}}}
}
//select排序
void select(int arr[],int len)
{int min=0;int t1=0;for(int i=0;i<len-1;i++){min=i;for(int j=i+1;j<len;j++){if(arr[min]>arr[j]){min=j;}}if(min!=i){t1=arr[min];arr[min]=arr[i];arr[i]=t1;}}
}
//直接插入排序
void sort(int arr[],int len)
{for(int i=1;i<len;i++){int j;int temp=arr[i];for( j=i-1;j>=0&&arr[j]>temp;j--){arr[j+1]=arr[j];}arr[j+1]=temp;}
}
//插入排序
void quick_sort(int arr[],int low,int high)
{//基准值int key=arr[low];int start=low,end=high;if(low>=high) return ;while(low<high)
{//high开始比较while(low<high&&arr[high]>=key){high--;}if(low<high){arr[low++]=arr[high];}//low那边开始比较while(low<high&&arr[low]<=key){low++;}if(low<high){arr[high--]=arr[low];}
}arr[low]=key;quick_sort(arr,start,low-1);quick_sort(arr,low+1,end);}int main(int argc, const char *argv[])
{int arr[]={23,24,12,5,33,5,34,7};int len=sizeof(arr)/sizeof(arr[0]);puts("bubb:");bubb(arr,len);for(int i=0;i<len;i++){printf("%d ",arr[i]);}puts("");return 0;
}
[ub
#include<stdio.h>
#include<string.h>
int number(int n)
{if(!n) return 0;return n%10+number(n/10);
}
int main(int argc, const char *argv[])
{puts("please input n:");int n;scanf("%d",&n);int sum=number(n);printf("sum=%d",sum);return 0;
}
#include<stdio.h>
#include<string.h>
#define swap(a,b) { int t=a;a=b;b=t;printf("%d %d",a,b);}
int main(int argc, const char *argv[])
{int n,i=0;puts("please input n:");scanf("%d",&n);int arr[100];while(n){arr[i]=n%2;n=n/2;i++;}printf("一共有%d位:",i);for(int j=0;j<i;j++){printf("%-5d",arr[j]);}puts("");puts("swap:");int k=1;for(int j=0;j+2<i;j++){int A=arr[j];int B=arr[j+1];swap(A,B);k=k*2;}printf(" %d",arr[k]);return 0;
}