二分查找
3 int binary_search(int *a,int len,int value)
4 {
5 int low,high,mid;
6 low=0;
7 high=len-1;
8 while(low<=high)
9 {
10 mid=(low+high)/2;
11 if(value<a[mid])
12 {
13 high=mid-1;
14 }
15 else if(value >a[mid])
16 {
17 low =mid+1;
18 }
19 else
20 return mid;
21 }
22 }
23 int main()
24 {
25 int b;
26 int a[10]={1,2,5,7,9,13,16,18,23,34};
27 b=binary_search(a,10,1);
28 printf("%d ",b);
29 return 0;
30 }
fibo
1 #include<stdio.h>
2
3 int main()
4 {
5 int a=1;
6 int i;
7 int b=1;
8 for(i=0;i<5;i++)
9 {
10 int c=a+b;
11 a=b;
12 b=c;
13 }
14 printf("%d ",b);
15 return 0;
16 }