//函数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将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。的更多相关文章

  1. AC日记——判断字符串是否为回文 openjudge 1.7 33

    33:判断字符串是否为回文 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...

  2. C#进行回文检测,判断字符串是否是回文的代码

    下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...

  3. 用递归方法判断字符串是否是回文(Recursion Palindrome Python)

    所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...

  4. YTU 2802: 判断字符串是否为回文

    2802: 判断字符串是否为回文 时间限制: 1 Sec  内存限制: 128 MB 提交: 348  解决: 246 题目描述 编写程序,判断输入的一个字符串是否为回文.若是则输出"Yes ...

  5. Java - 判断字符串是否是回文

    首先,回文是指类似于“12345”,“abcdcba”的形式,即正念和反念都是一样的字符串 判断字符串是否是回文,这边介绍3种办法 将字符串翻转,判断翻转后的字符串和原字符串是否相等 public s ...

  6. type-of-python作业-判断字符串是否属于回文需要忽略其中的标点、空格与大小写

    type-of-python作业 作业练习:要想检查文本是否属于回文需要忽略其中的标点.空格与大小写.例如,"Rise to vote, sir."是一段回文文本,但是我们现有的程 ...

  7. 判断字符串是否为回文 python

    回文正序和逆序一样的字符串,例如abccba 方法一 def is_palindrome1(text): l = list(text) l.reverse() t1 = ''.join(l) if t ...

  8. Java判断一个字符串是否是回文

    package com.spring.test; /** * 判断字符串是否为回文 * * @author liuwenlong * @create 2020-08-31 11:33:04 */ @S ...

  9. javascript判断给定字符串是否是回文

    //判断给定字符串是否是回文     function isPalindrome(word) {         var s = new Stack();         for (var i = 0 ...

随机推荐

  1. HITCON-Training-Writeup

    HITCON-Training-Writeup 原文链接M4x@10.0.0.55 项目地址M4x's github,欢迎star~ 更新时间5月16 复习一下二进制基础,写写HITCON-Train ...

  2. 接口自动化框架(Pytest,Allure,Yaml)

    框架链接:https://www.jianshu.com/p/e31c54bf15ee 目前是基于他的框架做了些改动(主要是session.action()和json格式传参). 后续优化,应该主要思 ...

  3. qml-main.cpp中的两种启动Qt Quick App模式

     现有两种启动Qt Quick App 模式: QQmlApplicationEngine搭配Window. QQuickView搭配Item.  qt默认使用第一种方法. QQmlApplicati ...

  4. String.valueOf()和toString()的区别

    1.String.valueOf(): Object obj=null; String str=""; str=String.valueOf(obj); //str=obj.toS ...

  5. 关于python 的 __future__

    经常看到__future__: from __future__ import absolute_importfrom __future__ import print_functionfrom __fu ...

  6. go-redis 基于beego正确使用序列化存储数据和反序列化获取数据

    安装go-redis // 安装命令 go get github.com/gomodule/redigo/redis // 导入使用 import( "github.com/gomodule ...

  7. HTML连载60-水平居中与设计一个团购界面

    一.水平居中 1.margin:0 auto在绝对定位中就失效了 2.如何让绝对定位的元素水平居中? 只需要设置绝对定位元素的left:50%:然后再设置绝对定位元素的margin-left:-元素宽 ...

  8. C++之Boost准标准库配置

    下载安装 进入官网下载地址:https://www.boost.org/users/download/ 本教程直接下载官方已编译库,不涉及源代码手动编译 点击官方编号好的链接,然后进入一个下载地址:h ...

  9. 远程操作Linux主机

    通过putty文件访问: 下载路径:https://the.earth.li/~sgtatham/putty/0.70/w32/putty-0.70-installer.msi 通过Python文件执 ...

  10. go之二进制协议gob和msgpack

    文章引用自 二进制协议gob和msgpack介绍 本文主要介绍二进制协议gob及msgpack的基本使用. 最近在写一个gin框架的session服务时遇到了一个问题,Go语言中的json包在序列化空 ...