- 博客(5)
- 收藏
- 关注
原创 strrchr函数的实现
#include #include #include const char* my_strrchr(char const *str,int ch)//const保护源字符串 { int len=strlen(str); const char *last=str+len-1;//定义一个变量last,指向str的最后一个字符 assert(str!=NULL); while(*last
2015-04-09 22:06:07
1420
原创 strchr函数的实现,顺序在字符串中寻找所需字符
#include #include const char* my_strchr(char const *str,int ch)//const保护源字符串不被改变 { assert(str!=NULL&&ch!=NULL);//断言:str和ch不为空 while(*str!='\0') { if(*str==ch) return str; ++str; } return
2015-04-09 21:52:35
461
原创 递归实现最大公约数:辗转相除法
#include int gyueshu(int a,int b) { int temp;//定义一个变量temp while(temp) { temp=a%b;//a与b取余赋给temp a=b; b=temp; } return a;//循环结束,返回a值,即最大公约数 } int main() { printf("%d\n",gyueshu(12,3));//调用g
2015-04-07 20:31:20
941
原创 用递归实现n的k次方
#include int my_power(int n,int k) { if(k==0) { return 1;//n的0次方为1 } else if(k==1) { return n;//n的1次方为n } else { return n*my_power(n,k-1);//递归 } } int main() { int ret=my_power(2,5);
2015-04-07 20:07:12
620
原创 strcat函数——字符串连接函数
#include #include #include char *my_strcpy(char *dest,char const *src) { char *temp=dest; assert((dest!=NULL&&src!=NULL)); while(*dest++=*src++) { ; } return temp; } int main() { c
2015-03-28 11:36:52
774
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅