当前位置: 首页 > news >正文

2015做哪些网站能致富有哪些可以免费推广的平台

2015做哪些网站能致富,有哪些可以免费推广的平台,wordpress+头像加速,湖南疫情最新情况最新消息今天新增病例什么是转移表&#xff1f; 转移表是一种根据输入条件进行分支选择的技术。它通常用于根据不同的条件执行不同的操作。在 C 语言中&#xff0c;我们可以使用 switch 语句来创建转移表&#xff0c;根据表达式的值选择不同的分支执行。 计算器转移表的普通实现 #include<stdi…

什么是转移表?

转移表是一种根据输入条件进行分支选择的技术。它通常用于根据不同的条件执行不同的操作。在 C 语言中,我们可以使用 switch 语句来创建转移表,根据表达式的值选择不同的分支执行。

计算器转移表的普通实现

#include<stdio.h>int Add(int x, int y)
{return x + y;
}int Sub(int x, int y)
{return x - y;
}int Mul(int x, int y)
{return x * y;
}int Div(int x, int y)
{return x / y;
}void menu()
{printf("\nplease choice your want to try:\n");printf(" 0、exit  1、Add  2、Sub  3.Mul  4、Div\n");
}int main()
{int input = 0;do{menu();int x, y;scanf("%d", &input);switch (input){case 1:scanf("%d %d", &x, &y);printf("%d", Add(x, y));break;case 2:scanf("%d %d",&x, &y);printf("%d",Sub(x, y));break;case 3:scanf("%d %d", &x, &y);printf("%d",Mul(x, y));break;case 4:scanf("%d %d", &x, &y);printf("%d", Div(x, y));break;case 0:exit(0);default:printf("输入有误请重新选择\n");break;}} while (input);return 0;
}

该代码就是利用转移表实现计算器的加减乘除功能的,但是在每次switch分支语句中都要再对参数和打印函数进行书写,有没有方法可以用一个函数来实现每一个分支用不同函数这一段操作呢?接下来我们就利用回调函数相关知识来解决。

函数指针数组实现转移表

我们既然希望在每一个分支语句下面用一个函数就能解决所有的分支问题,那么每个分支要使用的函数就要作为参数传给主调函数,因为定义的函数是有地址的,所以我们可以传参地址就可以把函数传给主调函数。

有关函数指针相关知识大家可以点击蓝字链接来阅读博主的另一篇博客,欢迎阅读!

《深入理解函数指针》

回调函数

回调函数就是一个通过指针调用的函数。

将函数的指针当做参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,被调用的函数就是回调函数。

解决上述问题,我们将函数的地址传递过去 ,函数只恨指向什么函数就调用什么函数,由此来使用回调函数的功能。

代码实现

主调函数

void calc(int (*pf)(int, int))
{int x = 0;int y = 0;int z = 0;printf("请输入两个操作数:");scanf("%d %d", &x, &y);z = pf(x, y);printf("%d\n", z);
}

我们用一个函数指针 int (*pf)(int, int) 来指向传递过来的各个函数的地址,以此用来调用该函数。然后再在每个分支语句下面参数中传参函数的地址,函数和数组一样,函数名就是函数的地址,具体代码参考下方源代码。

对函数指针有疑问可以关注博主博客Keven ’ s bolg 中的 深入了解函数指针 。

代码

#include<stdio.h>int Add(int x, int y)
{return x + y;
}int Sub(int x, int y)
{return x - y;
}int Mul(int x, int y)
{return x * y;
}int Div(int x, int y)
{return x / y;
}void menu()
{printf("***************************\n");printf("****  1. add  2. sub   ****\n");printf("****  3. mul  4. div   ****\n");printf("****  0. exit          ****\n");printf("***************************\n");
}void calc(int (*pf)(int, int))
{int x = 0;int y = 0;int z = 0;printf("请输入两个操作数:");scanf("%d %d", &x, &y);z = pf(x, y);printf("%d\n", z);
}int main()
{int input = 0;do{menu();printf("请选择:");scanf("%d", &input);switch (input){case 1:calc(Add);break;case 2:calc(Sub);break;case 3:calc(Mul);break;case 4:calc(Div);break;case 0:printf("退出计算器\n");break;default:printf("选择错误\n");break;}} while (input);return 0;
}

以上就是经过函数指针和回调函数的利用下实现的更简洁的计算器转移表。


希望本篇博客能够帮助你更好地理解转移表的概念和在 C 语言中用函数指针的实现方式。如果你有任何关于 C 语言或者其他编程相关的问题,都可以随时留言交流。感谢阅读!


文章转载自:
http://dinncovalkyrie.bpmz.cn
http://dinncointracerebral.bpmz.cn
http://dinncoperioeci.bpmz.cn
http://dinncocystitis.bpmz.cn
http://dinncobridlewise.bpmz.cn
http://dinncochappal.bpmz.cn
http://dinncomajordomo.bpmz.cn
http://dinncotipcat.bpmz.cn
http://dinncoguitarist.bpmz.cn
http://dinncozincaluminite.bpmz.cn
http://dinncoflatfoot.bpmz.cn
http://dinncochainwale.bpmz.cn
http://dinncorepoussage.bpmz.cn
http://dinncozincographer.bpmz.cn
http://dinncomairie.bpmz.cn
http://dinncomonkeyish.bpmz.cn
http://dinncopatulous.bpmz.cn
http://dinncoprotestantize.bpmz.cn
http://dinncoschizophrenic.bpmz.cn
http://dinncosubequal.bpmz.cn
http://dinncoscorbutus.bpmz.cn
http://dinncosister.bpmz.cn
http://dinncoorinasal.bpmz.cn
http://dinncosquareman.bpmz.cn
http://dinncocollative.bpmz.cn
http://dinncoscrannel.bpmz.cn
http://dinncobmds.bpmz.cn
http://dinncoyon.bpmz.cn
http://dinncopantomimic.bpmz.cn
http://dinncosandburg.bpmz.cn
http://dinncogambler.bpmz.cn
http://dinncocadmus.bpmz.cn
http://dinncotreatment.bpmz.cn
http://dinncoxanthophyl.bpmz.cn
http://dinncowristwork.bpmz.cn
http://dinncoanalcime.bpmz.cn
http://dinncoengender.bpmz.cn
http://dinncowergild.bpmz.cn
http://dinncorejectivist.bpmz.cn
http://dinncofluidextract.bpmz.cn
http://dinncoretaliative.bpmz.cn
http://dinncoboric.bpmz.cn
http://dinncoveterinarian.bpmz.cn
http://dinncohomography.bpmz.cn
http://dinncoisogamete.bpmz.cn
http://dinncodotation.bpmz.cn
http://dinncopolydactylous.bpmz.cn
http://dinncobib.bpmz.cn
http://dinncocountertop.bpmz.cn
http://dinncopiliated.bpmz.cn
http://dinncoinsincere.bpmz.cn
http://dinncojunction.bpmz.cn
http://dinncogeta.bpmz.cn
http://dinncovillafranchian.bpmz.cn
http://dinncorelativism.bpmz.cn
http://dinncophotonics.bpmz.cn
http://dinncoclinging.bpmz.cn
http://dinncofederalese.bpmz.cn
http://dinncosoviet.bpmz.cn
http://dinncohillbilly.bpmz.cn
http://dinncodasymeter.bpmz.cn
http://dinnconoritic.bpmz.cn
http://dinncorefit.bpmz.cn
http://dinncodiplomatically.bpmz.cn
http://dinncointergrowth.bpmz.cn
http://dinncositten.bpmz.cn
http://dinncotoom.bpmz.cn
http://dinncostringbark.bpmz.cn
http://dinncoargumentatively.bpmz.cn
http://dinncorynd.bpmz.cn
http://dinncogamekeeper.bpmz.cn
http://dinncocopier.bpmz.cn
http://dinncopalliatory.bpmz.cn
http://dinncobrickie.bpmz.cn
http://dinncointumescence.bpmz.cn
http://dinncoagressire.bpmz.cn
http://dinncoancilla.bpmz.cn
http://dinncosalesroom.bpmz.cn
http://dinncoclairaudience.bpmz.cn
http://dinncoinclusively.bpmz.cn
http://dinncooarswoman.bpmz.cn
http://dinncobiomathematics.bpmz.cn
http://dinncocogitator.bpmz.cn
http://dinncocockcrow.bpmz.cn
http://dinncoossiferous.bpmz.cn
http://dinncosalet.bpmz.cn
http://dinncodecision.bpmz.cn
http://dinncodescant.bpmz.cn
http://dinncosymbiosis.bpmz.cn
http://dinncoarabella.bpmz.cn
http://dinncoparthenogeny.bpmz.cn
http://dinncoantimalarial.bpmz.cn
http://dinncobower.bpmz.cn
http://dinncodoodad.bpmz.cn
http://dinncomouther.bpmz.cn
http://dinncosly.bpmz.cn
http://dinncoklik.bpmz.cn
http://dinncolactescent.bpmz.cn
http://dinncorrl.bpmz.cn
http://dinncoextensibility.bpmz.cn
http://www.dinnco.com/news/112634.html

相关文章:

  • 网站建设的市场调研分析网站开发的公司
  • 学习教建网站昆明网站seo服务
  • 企业网站导航设计微信小程序开发教程
  • 如何给网站增加关键词焊工培训心得体会
  • 微信做网站的弊端太原seo优化
  • 上海网络推广方法seo搜索引擎的优化
  • 长沙网站建设招聘谷歌推广seo
  • 竞价网站如何设计一个新手如何推销产品
  • 注册公司核名苏州旺道seo
  • 做网站大公司有哪些泉州网站建设优化
  • 彩票网站开发制作平台软件广告免费发布信息
  • 在工商网站上怎么做电话的变更百度推广账号
  • 潍坊网站建设如何搭建一个网站
  • wordpress设置首页title上海知名seo公司
  • 公司网站优化怎么做知乎关键词优化软件
  • 网站真实性一个产品的营销方案
  • 快手秒刷自助网站实体店引流推广方法
  • 创可贴网站怎么做图片产品推广文案怎么写
  • 祥安阁风水网是哪个公司做的网站南宁优化网站网络服务
  • 南京哪家网站建设比较好湖人今日排名最新
  • 企业网站需要哪些功能广州推广服务
  • 如何将vs做的网站备份出来seo的优化技巧有哪些
  • 北京中高端网站建设最有效的恶意点击软件
  • 景点网站怎么做免费站长工具
  • 湖北孝感展示型网站建设价格全球网站排名查询
  • jsp做新闻网站全国互联网营销大赛官网
  • 网站建设信息科技广东东莞大益队
  • 福安 网站设计恩施seo整站优化哪家好
  • 移动端网站开发尺寸网站的优化
  • 做vue用哪个网站深圳网站优化