Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

【C语言】递归和非递归分别实现strlen

今天带大家一起学习一下用递归和非递归分别实现strlen,对啦,这篇文章用的是C语言,这个大家应该会很熟悉吧,快来看看吧。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Strlen1(char* str) {//递归
	if (*str == '[+++]') {
		return 0;
	}
	else {
		return Strlen1(str + 1) + 1;
	}
}
//************
int Strlen2(char* str) {//非递归
	int n = 0;
	while (*str != '[+++]') {
		++str;
		++n;
	}
	return n;
}
void main() {
	char str[30] = { 0 };
	printf("请输入一串字符\n");
	scanf("%s", &str);
	printf("递归判断字符串长度是:%d\n", Strlen1(str));
	printf("非递归判断字符串长度是:%d\n", Strlen2(str));
	system("pause");
}

【推荐课程:C视频教程】

以上就是【C语言】递归和非递归分别实现strlen的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 29, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

【C语言】递归和非递归分别实现strlen

今天带大家一起学习一下用递归和非递归分别实现strlen,对啦,这篇文章用的是C语言,这个大家应该会很熟悉吧,快来看看吧。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Strlen1(char* str) {//递归
	if (*str == '') {
		return 0;
	}
	else {
		return Strlen1(str + 1) + 1;
	}
}
//************
int Strlen2(char* str) {//非递归
	int n = 0;
	while (*str != '[+++]') {
		++str;
		++n;
	}
	return n;
}
void main() {
	char str[30] = { 0 };
	printf("请输入一串字符\n");
	scanf("%s", &str);
	printf("递归判断字符串长度是:%d\n", Strlen1(str));
	printf("非递归判断字符串长度是:%d\n", Strlen2(str));
	system("pause");
}

【推荐课程:C视频教程】

以上就是【C语言】递归和非递归分别实现strlen的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 29, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

【C语言】递归和非递归分别实现strlen_C_内存溢出

【C语言】递归和非递归分别实现strlen

【C语言】递归和非递归分别实现strlen,第1张

【C语言】递归和非递归分别实现strlen

今天带大家一起学习一下用递归和非递归分别实现strlen,对啦,这篇文章用的是C语言,这个大家应该会很熟悉吧,快来看看吧。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Strlen1(char* str) {//递归
	if (*str == '') {
		return 0;
	}
	else {
		return Strlen1(str + 1) + 1;
	}
}
//************
int Strlen2(char* str) {//非递归
	int n = 0;
	while (*str != '') {
		++str;
		++n;
	}
	return n;
}
void main() {
	char str[30] = { 0 };
	printf("请输入一串字符\n");
	scanf("%s", &str);
	printf("递归判断字符串长度是:%d\n", Strlen1(str));
	printf("非递归判断字符串长度是:%d\n", Strlen2(str));
	system("pause");
}

【推荐课程:C视频教程】

以上就是【C语言】递归和非递归分别实现strlen的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/686364.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-21
下一篇 2022-04-21

发表评论

登录后才能评论

评论列表(0条)

保存