C语言:判断字符串是否为回文,-函数fun将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。
//函数fun功能:用函数指针指向要调用的函数,并进行调用。
#include <stdio.h>
double f1(double x)
{ return x*x; }
double f2(double x, double y)
{ return x*y; }
double fun(double a, double b)
{
/**********found**********/
double (*f)();//定义一个指针函数。
double r1, r2;
/**********found**********/
f = f1;
r1 = f(a);
/**********found**********/
f = f2;
r2 = (*f)(a, b);
return r1 + r2;
}
void main()
{ double x1=, x2=, r;
r = fun(x1, x2);
printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n",x1, x2, r);
}
//建立一个带头节点的单向链表,并用随机函数为各个结点赋值,函数fun将单向链表结点数据域为偶数的值累加起来。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct aa
{ int data;
struct aa *next;
} NODE;
int fun (NODE *h)
{ int sum=;
NODE *p;
p=h->next;//首结点
/*************found**************/
while(p!=NULL)//注意
{ if(p->data%==)
sum+=p->data;
/*************found**************/
p=p->next;
}
return sum;
}
NODE *creatlink(int n)
{
NODE *h,*p,*s;
int i;
h=p=(NODE*)malloc(sizeof(NODE));
for(i=;i<n;i++)
{
s=(NODE*)malloc(sizeof(NODE));
s->data=rand()%;
s->next=p->next;
p->next=s;
p=p->next;
}
p->next=NULL;
return h;
}
void outlink(NODE *h)
{ NODE *p;
p=h->next;
printf("\n\n The LIST :\n\n HEAD");
while(p)
{ printf("->%d",p->data);
p=p->next;}
printf("\n");
}
void main()
{ NODE *head; int sum;
system("CLS");
head=creatlink();
outlink(head);
sum=fun(head);
printf("\nSUM=%d",sum);
}
//函数功能:判断字符串是否为回文,若是返回1,主函数输出YES。回文是指顺读和倒读都一样的字符串。
#include <stdio.h>
#define N 80
int fun(char *str)
{
char *p = str;
char *q = str + strlen(str) - ;
while (*p == *q)
{
p++; q--;
if (p >= q)
{
return ;
}
}
return ;
} void main()
{
char s[N];
FILE *out;
char *test[]={"","","","abcdCBA"};
int i;
printf("Enter a string : ");
gets(s);
printf("\n\n");
puts(s);
if(fun(s))
printf("YES\n");
else
printf("NO\n");
/************************************/
out=fopen("out.dat","w");
for(i=;i<;i++)
if(fun(test[i]))
fprintf(out,"YES\n");
else
fprintf(out,"NO\n");
fclose(out);
/************************************/
}
C语言:判断字符串是否为回文,-函数fun将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。的更多相关文章
- AC日记——判断字符串是否为回文 openjudge 1.7 33
		
33:判断字符串是否为回文 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...
 - C#进行回文检测,判断字符串是否是回文的代码
		
下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...
 - 用递归方法判断字符串是否是回文(Recursion Palindrome Python)
		
所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...
 - YTU 2802: 判断字符串是否为回文
		
2802: 判断字符串是否为回文 时间限制: 1 Sec 内存限制: 128 MB 提交: 348 解决: 246 题目描述 编写程序,判断输入的一个字符串是否为回文.若是则输出"Yes ...
 - Java - 判断字符串是否是回文
		
首先,回文是指类似于“12345”,“abcdcba”的形式,即正念和反念都是一样的字符串 判断字符串是否是回文,这边介绍3种办法 将字符串翻转,判断翻转后的字符串和原字符串是否相等 public s ...
 - type-of-python作业-判断字符串是否属于回文需要忽略其中的标点、空格与大小写
		
type-of-python作业 作业练习:要想检查文本是否属于回文需要忽略其中的标点.空格与大小写.例如,"Rise to vote, sir."是一段回文文本,但是我们现有的程 ...
 - 判断字符串是否为回文 python
		
回文正序和逆序一样的字符串,例如abccba 方法一 def is_palindrome1(text): l = list(text) l.reverse() t1 = ''.join(l) if t ...
 - Java判断一个字符串是否是回文
		
package com.spring.test; /** * 判断字符串是否为回文 * * @author liuwenlong * @create 2020-08-31 11:33:04 */ @S ...
 - javascript判断给定字符串是否是回文
		
//判断给定字符串是否是回文 function isPalindrome(word) { var s = new Stack(); for (var i = 0 ...
 
随机推荐
- 实用sql语句合集
			
1. 将选取A表的name字段 然后选择A表和B表,最后进行id相等比较 最终得到的是合集 $res = \DB::select("SELECT name FROM users,car_a ...
 - 深度学习之numpy.poly1d()函数
			
1.np.poly1d()此函数有两个参数: 参数1:为一个数组,若没有参数2,则生成一个多项式,例如: p = np.poly1d([2,3,5,7]) print(p) ==>> ...
 - istio部署-istio jaeger & kiali
			
参考 fleeto/sleep fleeto/flaskapp jaegertracing/jaeger kiali kiali/kiali kiali/kiali-ui kiali/kiali/ta ...
 - AcWing 874. 筛法求欧拉函数
			
#include<bits/stdc++.h> using namespace std; typedef long long ll; ; int primes[N],cnt; int ph ...
 - 同步异步IO,阻塞非阻塞
			
同步异步 同步IO操作:导致请求进程阻塞,知道IO操作完成. 异步IO操作:不导致进程阻塞. 在处理(网络) IO 的时候,阻塞和非阻塞都是同步IO, 阻塞,就是调用我(函数),我(函数)没有接收完数 ...
 - python的os库
			
os库(operating system,提供操作系统函数) 1. __file__是什么? ans:当前文件的名字. 例如r.py内容如下 import os if __name__ == &quo ...
 - 每天进步一点点------Nios II 的Run as hardware 中报错:Downloading ELF Process failed
			
今天继续调试,又出现了新问题.在执行NIOS程序代码时,不能下载了:Pausing target processor: not responding. Resetting and trying aga ...
 - python 多线程,多进程,高效爬虫
			
1.多线程from concurrent.futures import ThreadPoolExecutor import requests def fetch_async(url): respons ...
 - 各技能DBC参数
			
推荐你 通过 引擎的帮助文件查找标准魔法DB 下面是 部分hero引擎的标准魔法DB 34,解毒术,2,26,16,0,0,0,0,0,2,42,50,44,100,46,200,40,, 35,老 ...
 - Unity小知识点大全(一)
			
原帖地址:https://zhuanlan.zhihu.com/p/54763553 1. 高亮选择 在Scene面板右上角的Gizmo下拉列表中,可以通过设置Selection Outline选项决 ...