当前位置:网站首页>【C语言】封装接口(加减乘除)
【C语言】封装接口(加减乘除)
2022-06-12 03:43:00 【嵌入式职场】
目录
1、operator.h
//
// Created by cjs0719 on 2022/6/11.
//
#ifndef TEST_OPERATOR_H
#define TEST_OPERATOR_H
typedef struct {
double (* Add)(double n, double m);
double (* Sub)(double n, double m);
double (* Mul)(double n, double m);
double (* Div)(double n, double m);
}FAN_OPERATOR;
extern FAN_OPERATOR FanOperator;
void InitOperator(void);
#endif //TEST_OPERATOR_H
2、operator.c
//
// Created by cjs0719 on 2022/6/11.
//
#include "operator.h"
#include <stdio.h>
#include <stdlib.h>
static double add(double n, double m)
{
return m + n;
}
static double sub(double n, double m)
{
return n - m;
}
static double mul(double n, double m)
{
return n * m;
}
static double divnum(double n, double m)
{
if(m == 0)
{
printf("除数不能为0,m=%f",m);
return 0.0;
}
return n/m;
}
void InitOperator(void)
{
FanOperator.Add = add;
FanOperator.Sub = sub;
FanOperator.Mul = mul;
FanOperator.Div = divnum;
}3、测试入口
#include <stdio.h>
#include "operator.h"
FAN_OPERATOR FanOperator;
int main() {
InitOperator();
double addnum = FanOperator.Add(23,56);
printf("addnum:%.2f\n",addnum);
double subnum = FanOperator.Sub(12,23);
printf("subnum:%.2f\n",subnum);
double mulnum = FanOperator.Mul(20,30);
printf("mulnum:%.2f\n",mulnum);
double divnum = FanOperator.Div(24,3);
printf("divnum:%.2f\n",divnum);
return 0;
}输出结果展示:

边栏推荐
- Yyds dry inventory MySQL learning - how transactions are isolated
- [DFS "want" or "don't"] seek subsets; Seeking combination
- Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
- vim命令大全
- Data flow diagram of Flink
- 顺序表与链表-----进阶
- Convert py file to EXE file
- Introduce the functions of the new project aleo
- 3768 string pruning (double pointer)
- CA证书及密钥对应用笔记
猜你喜欢

central limit theorem

JSP实现银柜台业务绩效考核系统

Data flow diagram of Flink

E-commerce middle office system architecture

ics-07

(idea)the file size(2.85M) exceeds configured limit(2.56M).Code insight features are not available问题

MySQL的check约束数字问题

如何修改mysql 查询出来的结果名称 结果1,结果2

Redis gets the set of keys prefixed with XXX

Drop down menu dropdown yyds dry inventory of semantic UI
随机推荐
微服务概念及介绍
MongoDB精华总结
MySQL的check约束数字问题
R语言plotly可视化:使用plotly可视化简单线性回归模型的回归线(simple regression model linear regression plots)
R language uses the coxph function of survival package to build Cox regression model, uses the ggrisk function of ggrisk package to visualize the risk score map (risk score map) of Cox regression, and
fastjson开启safeMode,关闭autoType,去除安全漏洞
Go syntax variable
[Business Research Report] 2021 global mobile game player white paper - download link attached
Message queuing overview
TCP three handshakes and four waves
Lighting Basics: optical model
R语言plotly可视化:可视化回归模型实际值和回归预测值的散点图分析回归模型的预测效能、区分训练集和测试集、一个好的模型大部分的散点在对角线附近、添加边缘直方图以快速诊断模型可能存在的任何预测偏差
In 2022, don't you know the difference between arrow function and ordinary function?
The rise of another domestic mobile phone chip is close to the height reached by Huawei
Final summary of addition, deletion, modification and query
[Bank Research Report] technology enabled retail finance carbon neutral development report (2022) - download link attached
What is the core of Web3?
FOB,CIF,CFR的区别是什么?
[Yugong series] March 2022 asp Net core Middleware - current limiting
C language array