int sumValue(int x, int y) {
return x + y;
}
int subValue(int x, int y) {
return x - y;
}
int temp = 0;
int gcdValue(int x, int y) {//greatest common divisor 最大公约数
if (x > y) {//使得x存储小值, y存储大值
temp = x;
x = y;
y = temp;
}
int gcd = 0;
for (int i = x; i > 1; i--) {
if ((x % i == 0) && (y % i == 0)) {
gcd = i;
break;
}
}
return gcd;
}
int lcmValue(int x, int y) {//lowest common multiple 求最小公倍数
if (x > y) {//使得x存储小值, y存储大值
temp = x;
x = y;
y = temp;
}
int lcm = 0;
for (int i = y; i <= x * y; i++) {
if ((i % x == 0) && (i % y == 0)) {
lcm = i;
break;
}
}
return lcm;
}
typedef int (*PFUN) (int, int);
typedef struct operatorFctPair {
char operator;//存储运算符
PFUN function;//存储函数地址
}OperatorFctPair;
//operator是用户输入的运算符, p用来接收匹配表, count是匹配表中成员的个数
PFUN getFctByopetator(char operator, OperatorFctPair *p, int count) {
for (int i = 0; i < count; i++) {
if ((p + i)->operator == operator) {
//如果找到对应的函数, 将函数地址返回
return (p + i)->function;
}
}
return NULL;
}
int computer(int x, int y, PFUN pFct, char operator, OperatorFctPair *pair, int count) {//动态调用
PFUN function = getFctByopetator(operator, pair, count);
return function(x, y);
}
int main(int argc, const char * argv[])
{
// 动态函数调用实现下列操作,输入2个数以及操作符计算结果。@求最大公约数 $求最小公倍数 -求差 +求和 等等
OperatorFctPair pair[4] = {
{'@', gcdValue},
{'$', lcmValue},
{'+', sumValue},
{'-', subValue}
};
char operatorName = 0;
int a = 0, b = 0;
printf("请输入要运算的两个整数和运算符:(@求最大公约数, $求最小公倍数, -求差, +求和)\n");
scanf("%d%c%d", &a, &operatorName, &b);
if (getFctByopetator(operatorName, pair, 4) != NULL) {
int result = computer(a, b, gcdValue, operatorName, pair, 4);
printf("%d %c %d = %d\n", a, operatorName, b, result);
} else {
printf("%c运算没有实现, 请按照提示进行输入\n", operatorName);
}
return 0;
}
相关推荐
求n个数的最大公约数及最小公倍数
一、题目分析 简单地说:就是求n个数的最大公约数、最小公倍数 复杂的说:还是求n个数的最大公约数、最小公倍数 哈哈哈,其实在之前的博客中列举了求解两个数的最大公约数的算法, 但是请注意这里的数据比较高大上一点,是n; 接下来:就是就是就是 我的分析思路:与大家共勉 (1)运用4种求解最大公约数算法写出求解两个数最大公约数的方法; (2)调用求解两个数的最大公约数方法,对n个数依次进行两两比较; (...
用c语言,通过输入两个数,调用函数并输出最大值
在 C 语言中,可以通过定义一个函数来输出两个数的最大值。 例如,可以定义一个名为 max 的函数,该函数接受两个参数 a 和 b,并返回这两个数的最大值。代码如下: #include <stdio.h> int max(int a, int b) { if (a > b) { return a; } else { return b; } } in...
三种方法求最大公约数及求n个数的最小公倍数
一、三种方法求两个数的最大公约数 (1) 辗转相除法 辗转相除法求最大公约数是一种常用的求两个数的最大公约数的方法。 方法是: 以小数除大数,如果能整除,那么小数就是所求的最大公约数。否则就用余数来除除数;再用新除法的余数去除刚才的余数。依此类推,直到一个除法能够整除,这时作为除数的数就是所求的最大公约数。 具体过程如下: 输入正整数m和n,保证m不小于n;
C语言求最大公倍数
题目描述 本题要求实现一个计算两个数的最小公倍数的简单函数。 函数接口定义: int LCM( int x, int y ); 其中x和y是两个正整数,函数LCM应返回这两个数的最小公倍数。 裁判测试程序样例: #include <stdio.h> int LCM( int x, int y ); int main() { int x, y; scanf("%d %d", &x, &y); printf("%d\n", LCM(x, y)); r
LaTex的下载与安装(2024小白+windows系统)
本文主要介绍了Latex的下载与安装,还包括安装过程中遇到的小问题的解决。
UUVsimulator仿真
pub -r 10 /cmd_vel geometry_msgs/Twist控制运动没有反应。通过键盘控制运动,接收不到/cmd_vel消息。
动态函数调用实现下列操作,输入2个数以及操作符计算结果。 @ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
// // main.m // HomeWrokFunctionPointer // // Created by lanouhn on 14-7-30. // Copyright (c) 2014年 Summer. All rights reserved. // #import //求两个数的差 int differenceValue(int x, int y) { retur
NPP/VIIRS夜间灯光数据下载和介绍
夜间灯光数据作为当前比较火热的研究数据,与其他遥感数据不同,它是通过DN值来体现所携带的信息,最常用的使用月度数据。 该数据数据量大,下载慢,相对来说较难快速获取。 一、数据下载 美国国家海洋大气管理局NOAA下属的NCEI国家环境信息中心Earth Observation Group。 二、月度数据文件介绍 从网站上下载的逐月的灯光数据文件是压缩包的形式,每月的数据包括vcm, vcmsl两个版本的压缩包,其中vcm版本排除了受杂散光影响的数据,vcmsl版本为辐射值经过杂散光校正程序后的数
动态函数调用实现下列操作,输入2个数以及操作符计算结果@ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
//求最大公约数 int greatestDivisorOfTwo(int x, int y){ int min = x < y ? x : y; int i = 0; for (int i = min; i > 0; i--) { if (x % i == 0 && y % i == 0) { break; }
“挑战杯”大赛“揭榜挂帅”赛道-baseline解析
在这个脚本中,txt文件的保存路径为'yolov7/datasets/Fatigue_driving_detection/txt_labels/',而xml文件的路径为'./label_xml/'。标注图片后的产物是会给每一个图片对应生成一个xml格式的文件,但是如果要用yolo框架去训练模型,输入的数据必须是txt格式,因此这里有一步转换格式的过程。注意看:obs这里有三个文件夹,第一个是关键帧的文件夹A,第二个是标注时输出的位置为文件夹B,第三个是智能标注后和手动标注的合集文件夹C。
大模型测试人员完整学习体系(分层成长路线 + 知识框架 + 落地实操)
本文系统构建了大模型测试工程师的4级能力成长体系:L1(测试执行)-L2(专项测试)-L3(质量体系)-L4(行业标准),详细拆解了每个阶段的核心技能图谱。重点包括:入门层需掌握传统测试基础和大模型产品逻辑;进阶层需精通Prompt用例设计、RAG测试、安全对齐、自动化评测等专项能力;高级层聚焦评测平台搭建与质量体系建设;专家层深入算法对齐与行业标准制定。文章配套提供了分阶段技术工具栈、3-12个月学习路径及5类实战项目建议,形成了一套完整的大模型测试人才能力培养框架。
最小公倍数 简单代码
#include<stdio.h>int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int main() { int a,b; scanf("%d%d",&a,&b); printf("%d",gcd(a,b)); //最大公约数 printf("%d",a*b/gcd(a,b)); ...
微信小程序 - 强力解决播放视频卡顿问题,小程序使用video组件播放视频或第三方视频插件,会出现卡顿或者无法播放的各种奇怪问题(微信小程序苹果ios/安卓播放视频很卡不流畅、视频太长或文件大等情况)
微信小程序视频组件播放卡顿,微信小程序video组件出现无法播放或卡顿,微信小程序video组件播放时会出现卡顿,微信小程序使用video组件播放视频的时候,会出现卡顿或者无法播放的问题,微信小程序安卓视频播放卡顿问题,微信小程序苹果ios手机播放视频不流畅很卡,加cdn还是卡,uniapp播放视频会有明显的卡顿问题,video视频时卡顿不流畅问题,为什么video组件播放视频卡顿?苹果微信小程序通过video组件播放视频时卡顿,怎么解决?微信小程序video组件出现无法播放或卡顿,设置custom-cac
//动态函数调用实现下列操作,输入2个数以及操作符计算结果。@ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
int maxDivisorFunction(int x, int y){//求最大公约数 int m = 0; if (x > y) { while (y != 0) { m = x % y; x = y; y = m; } return x;
Kimi Code国产AI编程助手安装使用详细教程
Kimi Code 开发者智能编程服务简介:Kimi Code 是专为开发者提供的 AI 编程辅助工具,基于旗舰模型 Kimi K3(2.8万亿参数,支持100万token上下文)。提供 CLI、VS Code 插件等形式,支持代码阅读、编辑等功能。用户可通过API Key接入第三方工具。安装简单(Windows/Mac/Linux一键脚本),需在官网生成API密钥并登录使用。注意账户需充值余额方可正常调用服务。
使用Captum库对CIFAR数据集进行模型可解释性分析
为了训练模型,我们需要指定损失函数和优化技术。损失函数用于衡量模型的性能,在训练过程中,我们通过调整模型参数来最小化损失。本教程使用。
动态函数调用实现下列操作,输入2个数以及操作符计算结果。@ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
int maxDivisorFunction(int x, int y){//求最大公约数 int m = 0; if (x > y) { while (y != 0) { m = x % y; x = y; y = m; } return x;
VC中sqlite的使用
在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示
2.、动态函数调用实现下列操作,输入2个数以及操作符计算结果。 @ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
#import #import "Final.h" int main(int argc, const char * argv[]) { // 2.、动态函数调用实现下列操作,输入2个数以及操作符计算结果。 // @ 求最大公约数 $求最小公倍数 // - 求差 + 求和 等等 NFP pair[4] = {//定以结构体,
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
//2.、动态函数调用实现下列操作,输入2个数以及操作符计算结果。@ 求最大公约数 $求最小公倍数 - 求差+ 求和 等等
#import //求最大公约数 int maxDivisor(int x, int y){ int i = 0; if (x < y) { for (int i = x; i > 0; i--) { if (x % i ==0 && y % i ==0) { break; }
锂电池充电器电路设计 里面有电路
锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。
求n个数的最大公约数和最小公倍数C++
一、问题描述 求n个数的最大公约数和最小公倍数。 二、解题思路 1、首先我们可以利用辗转相除法编写一个函数gcd(int a,int b)来求出两个数的最大公约数,然后将输入的n个数放进数组a[100]中,编写一个函数GCD(int a[],int n)函数利用for循环来依次求解每两个数的最大公约数,最后得到n个数的最大公约数。 2、求出两个数的最大公约数后,若k是a和b的最大公约数,那么a和...
JAVA求两个数的最小公倍数和最大公约数(两种方法)
JAVA求两个数的最小公倍数和最大公约数 输入两个数,求最小公倍数和最大公约数 例如,12和20的最大公约数是4,最小公倍数是60 代码 Scanner scan=new Scanner(System.in); System.out.println("请输入两个整数:"); int m=scan.nextInt(); int n=scan.nextInt(); int fan = 0,x=m,y=n; if(m<n) { //始终保持m比n大
C语言:求两个数的最大公约数和最小公倍数
C语言:求两个数的最大公约数和最小公倍数 求两个数的最大公约数:“辗转相除法”: 设两数为a和b(a>b),用a除以b,得a÷b=商…余数,若余数为0 ,则最大公约数为b;若余数不为0 ,则再用b÷余数, 得b÷余数=商1…余数1,若余数1=0,则最大公约数为余数,若余数1不为0,继续让商÷余数n,一直到能够余数为零 这时的除数即最大公约数。 求两个数的最小公倍数: 最小公倍数=两数的乘积÷...
C语言中求两个数的最大公约数和最小公倍数
Today,让我来带大家学习一下如何用C语言写出求两个数的最大公约数和最小公倍数的代码,这个方法不仅在C语言中有用,其他语言都可以用的。 首先,来看看怎么求最大公约数,求最大公约数需要用到欧几里得算法,也称为辗转相除法。算法就是用两数中较大的数a除以另一个数b得出余数c,然后判断c是否为0(意思a能够整除b),为0则b为最大公因数;反之,则把b作为a,c作为b,继续上面的操作,直至余数为0. ...
Java实现求n个数的最大公约数和最小公倍数
一、题目要求 求N个数的最大公约数和最小公倍数。用C或C++或java或python语言实现程序解决问题。 1.程序风格良好(使用自定义注释模板) 2.提供友好的输入输出,并进行输入数据的正确性验证。 二、算法分析 注:遵循一条数学定理:两数之积等于两数的最大公约数与最小公倍数之积 n个数的最大公约数和最小公倍数的求法是基于两个数的求法之上的: 1、先求两个数的最大公约数和最小公倍数 2、再用所求...
C++中实现求两个整数的最大公约数和最小公倍数
最大公约数:如果有一个自然数a能被自然数b整除,则称a为b的倍数,b为a的约数。几个自然数公有的约数,叫做这几个自然数的公约数。公约数中最大的一个公约数,称为这几个自然数的最大公约数。 这个有几种方法,下面是两种不错的方法: (1)求差判定法.如果两个数相差不大,可以用大数减去小数,所得的差与小数的最大公约数就是原来两个数的最大公约数.例如:求78和60的最大公约数.78-60=18,18和60
求N个数的最大公约数和最小公倍数以及Hankson"逆问题"(python)
求N个数的最大公约数和最小公倍数以及Hankson"逆问题"(python) 一、题目要求 1.基本要求: 求N个数的最大公约数和最小公倍数。用C或C++或java或python语言实现程序解决问题 2.提高要求: 已知正整数a0,a1,b0,b1,设某未知正整数x满足: (1)x和a0的最大公约数是a1; (2)x和b0的最小公倍数是b1。 输入数据保证a0能被a1整除,b1能被b0整除。 对于...
2663



被折叠的 条评论
为什么被折叠?



