C //练习 5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。

C程序设计语言 (第二版) 练习 5-4

练习 5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。

注意:代码在win32控制台运行,在不同的IDE环境下,有部分可能需要变更。
IDE工具:Visual Studio 2010
代码块:
c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int strend(char *s, char *t){
	int len1 = strlen(s);
	int len2 = strlen(t);
	for(int i = len2 - 1, j = len1 - 1; i >= 0; i--, j--){
		if(t[i] != s[j]){
			return 0;
		}
	}
	return 1;
}

int main(){
	char s[] = "hello";
	char t[] = "llo";
	printf("%d\n", strend(s, t));

	system("pause");
	return 0;
}
相关推荐
NAGNIP3 小时前
大模型框架性能优化策略:延迟、吞吐量与成本权衡
算法
美团技术团队4 小时前
LongCat-Flash:如何使用 SGLang 部署美团 Agentic 模型
人工智能·算法
Fanxt_Ja8 小时前
【LeetCode】算法详解#15 ---环形链表II
数据结构·算法·leetcode·链表
侃侃_天下8 小时前
最终的信号类
开发语言·c++·算法
茉莉玫瑰花茶9 小时前
算法 --- 字符串
算法
博笙困了9 小时前
AcWing学习——差分
c++·算法
NAGNIP9 小时前
认识 Unsloth 框架:大模型高效微调的利器
算法
NAGNIP9 小时前
大模型微调框架之LLaMA Factory
算法
echoarts9 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Python技术极客9 小时前
一款超好用的 Python 交互式可视化工具,强烈推荐~
算法