//函数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. Vue的iview组件框架select远程搜索,选中后不刷新的问题

    1.场景:弹框内有一个下拉组件(支持搜索),当选择完数据后弹框关闭,再次打开后,下拉框内的数据是刚才选中的数据.原因:分析后觉得是搜索内容没有清空,导致下拉的数据只有一个 2.解决方案 a .解决:调 ...

  2. C#中Dictionary的实现简述

    更详细的解析可以查看这篇文章:https://blog.csdn.net/zhaoguanghui2012/article/details/88105715 简要描述就是通过桶Buckets与Entr ...

  3. input:file上传文件类型(记录)

    imput 属性有以下几种: 1.type:input类型这就不多说了2.accept:表示可以选择的文件类型,多个类型用英文逗号分开,常用的类型见下表. <input id="fil ...

  4. C++-hihoCode-1105/1109-[STL][堆][prime]

    #include <set> #include <map> #include <cmath> #include <queue> #include < ...

  5. 5.springboot-------Yaml

    springboot配置文件: Yaml是什么玩意? Yaml的基本语法 编写规则 1.大小写敏感,同json: 2.通过缩进表示层级关系:符号含义 注意事项:字符串默认不需要加上单引号或双引号. # ...

  6. idea tomcat启动无效

    今天换了台电脑,用idea 部署tomcat启动死活启动不了,报 Application Server was not connected before run configuration stop, ...

  7. 最大/最小de K个数/第K个数

    题目 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 思路 堆排序 收获 用优先队列实现最大最小堆 注意下列代码中优先队列 ...

  8. 【C语言】定义一个函数,求长方体的体积

    #include<stdio.h> int volume(int a, int b,int c)/*定义函数*/ { int p; p = a * b * c; return p; } i ...

  9. phpstudy扩展mongoDB

    观察如下3个参数,即位数,ts/nts,vc9/vc11/……三条规则(一定要一一对应) 重要是,还要对应PHP的版本,我选的是5.6的对应的版本 去http://windows.php.net/do ...

  10. [vue学习]快速搭建一个项目

    安装node.js 官网:https://nodejs.org/en/ 淘宝NPM镜像(npm是外网,用国内代理下载安装贼快) $ npm install -g cnpm --registry=htt ...