两道想破脑袋的题- -求大神带飞
C:\Users\Admin\Desktop{:10_254:} 。。。。 #include <stdio.h>#include <string.h>
int search(char str[], char sub_str[])
{
int ret = 0;
int s = 0;
int str_len = strlen(str);
int sub_str_len = strlen(sub_str);
for(int i = 0; i < str_len; i++)
{
for(int j = 0; j < sub_str_len; j++)
{
if(str == sub_str)
{
s++;
}
else
{
s = 0;
break;
}
}
if(s == sub_str_len)
{
ret++;
}
}
return ret;
}
int main(void)
{
char *str = "asd asasdfg,asd as 16*67 asd10";
char *sub_str = "as";
int c = search(str, sub_str);
printf("子字符串 %s 共出现了%d次\n", sub_str, c);
return 0;
} 人造人 发表于 2016-12-12 13:40
谢谢大神带飞{:5_105:} #include <stdio.h>
#include <string.h>
unsigned long fibnocci(unsigned long n)
{
if(n == 0)
{
return 0;
}
if(n == 1)
{
return 1;
}
return fibnocci(n - 1) + fibnocci(n - 2);
}
int main(void)
{
int t = 99;
int i = 0;
for(i = 0; t > fibnocci(i); i++);
printf("t = %d i = %d fibnocci(i) = %ld\n", t, i, fibnocci(i));
printf("fibnocci(i - 1) = %ld\n", fibnocci(i - 1));
return 0;
}
页:
[1]