非递归实现:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
int strlen(char* str)
{
if (*str == '\0')
return 0;
else return 1 + strlen(str + 1);
}
int main()
{
char* p = "abcdef";
int len = strlen(p);
printf("%d\n", len);
system("pause");
return 0;
}
递归实现:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <stdlib.h>
int factorial(int n)
{
if (n <= 1)
return 1;
else
return( n* factorial(n - 1));
}
int main()
{
int n = 0;
int ret = 0;
printf("请输入一个数字:");
scanf("%d", &n);
ret = n * factorial(n - 1);
printf("%d\n", ret);
system("pause");
return 0;
}