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;
}
相关推荐
不穿格子的程序员13 分钟前
从零开始写算法——回溯篇4:分割回文串 + N皇后
算法·深度优先·dfs
小白学大数据15 分钟前
绕过拼多多 App 反抓包机制的综合逆向解决方案
开发语言·爬虫·python·自动化
使者大牙16 分钟前
【单点知识】 Python装饰器介绍
开发语言·数据库·python
带土118 分钟前
2. C++ private、protected、public
开发语言·c++
ScilogyHunter19 分钟前
qBI有什么用
算法·qbi
我不是8神21 分钟前
字节跳动 Eino 框架(Golang+AI)知识点全面总结
开发语言·人工智能·golang
古城小栈23 分钟前
Rust复合类型 四大军阀:数、元、切、串
开发语言·后端·rust
kong790692833 分钟前
Python核心语法-Python自定义模块、Python包
开发语言·python·python核心语法
龙山云仓1 小时前
No131:AI中国故事-对话荀子——性恶论与AI约束:礼法并用、化性起伪与算法治理
大数据·人工智能·深度学习·算法·机器学习
夏鹏今天学习了吗1 小时前
【LeetCode热题100(90/100)】编辑距离
算法·leetcode·职场和发展