This commit is contained in:
nonstriater
2014-05-13 09:19:55 +08:00
parent 1100bdabce
commit 16cf6be47e
13 changed files with 764 additions and 353 deletions
+47
View File
@@ -0,0 +1,47 @@
#include "stdio.h"
void generate(int a,int b,int N ,int * Q){
int p=1,q=1;
int tmpA,tmpB;
for (int i = 0; i < N; ++i)
{
tmpA = a*p;
tmpB = b*q;
if (tmpA>tmpB)
{
Q[i]=tmpB;
q++;
}
else if(tmpA<tmpB)
{
Q[i]=tmpA;
p++;
}
else{// ==
Q[i]=tmpA;
p++;
q++;
}
}
}
int main(int argc, char const *argv[])
{
int a[10];
generate(3,5,10,a);
for (int i = 0; i < 10; ++i)
{
printf(" %d \n", a[i]);
}
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
#include "stdio.h"
void print_continuous_sequence_sum(int n){// n=1,2
int small=1;
int big=2;
int sum = small+big;
while(small<big && big<=n/2+1){
if (sum==n)
{
printf("%d ,%d\n",small,big);
}
while(sum>n){
sum-=small;
small++;
if (sum==n)
{
printf("%d, %d\n",small,big);
}
}
big++;
sum+=big;
}
}
int main(int argc, char const *argv[])
{
print_continuous_sequence_sum(115);
return 0;
}
+55
View File
@@ -0,0 +1,55 @@
#include "stdio.h"
void reorder(int *data, int length){
int i=0;
int j=length-1;
while(i<j){
if (!isEvenNum(data[i]) )
{
i++;
continue;
}
if (isEvenNum(data[j]) )
{
j--;
continue;
}
//交换
int tmp ;
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
int isEvenNum(int n){
return (n&1) == 0;
}
int main(int argc, char const *argv[])
{
int a[]= {5,2,7,8,9,34,21,6};
reorder(a,8);
for (int i = 0; i < 8; ++i)
{
printf(" %d ", a[i]);
}
return 0;
}
@@ -0,0 +1,57 @@
#include "stdio.h"
#include "time.h"
int fibonacci(int n){
int result[2] = {0,1};
if (n<2)
{
return result[n];
}
return fibonacci(n-1)+fibonacci(n-2);
}
// 循环
int fibonacci2(int n){
int result[2] = {0,1};
if ( n<2 )
{
return result[n];
}
int fibOne=0;
int fibTwo=1;
int fibN;
for (int i = 2; i < n; ++i)
{
fibN = fibOne + fibTwo;
fibOne = fibTwo;
fibTwo = fibN;
}
return fibN;
}
int main(){
int start,end;
long result;
start = clock();
result=fibonacci2(40);
end = clock();
printf("%ld %.6fs",result,(double)(end-start)/CLOCKS_PER_SEC);
return 0;
}
+3 -2
View File
@@ -162,7 +162,8 @@ char first_appear_only_once(const char *source){
// 最大对称子串的长度
int max_symmetrical_char_length(const char *scr){
int max_symmetrical_length=1;
return 0;
@@ -243,7 +244,7 @@ char *strcpy(const char *src,char *dest){
// aabcd & bcad , abc&bca
BOOL isBrother(const char *first,const char *secd){
return YES;
}