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;
}
相关推荐
沐知全栈开发17 小时前
HTML 脚本:基础、应用与未来趋势
开发语言
@菜菜_达17 小时前
interact.js 前端拖拽插件
开发语言·前端·javascript
谈笑也风生17 小时前
经典算法题之子集(四)
算法
mit6.82418 小时前
划分dp+滑窗+前缀和|deque优化
算法
APIshop18 小时前
实战解析:苏宁易购 item_search 按关键字搜索商品API接口
开发语言·chrome·python
百***920218 小时前
java进阶1——JVM
java·开发语言·jvm
蓝桉~MLGT18 小时前
Python学习历程——Python面向对象编程详解
开发语言·python·学习
Evand J18 小时前
【MATLAB例程】2雷达二维目标跟踪滤波系统-UKF(无迹卡尔曼滤波)实现,目标匀速运动模型(带扰动)。附代码下载链接
开发语言·matlab·目标跟踪·滤波·卡尔曼滤波
larance18 小时前
Python 中的 *args 和 **kwargs
开发语言·python
Easonmax18 小时前
用 Rust 打造可复现的 ASCII 艺术渲染器:从像素到字符的完整工程实践
开发语言·后端·rust