当前位置:网站首页>(指针)编写函数void fun(int x,int *pp,int *n)
(指针)编写函数void fun(int x,int *pp,int *n)
2022-07-04 03:51:00 【我不是萧海哇~~~~】
功能:求出x的偶数因子,并按从小到大的顺序放在pp所指的数组中,这些因子的个数通过形参n返回(假设pp指向足够大的空间)。
如:x为24
则有六个数符合要求,2、4、6、8、12、24都保存到pp中n为p
Code:
void fun(int x,int *pp,int *n)
{
*pp=0;
*n=0;
int cnt=0;
for(int i=2;i<=x;i++)
{
if(x%i==0)
{
if(i%2==0)
{
if(*pp==0)
{
pp[cnt++]=i;
(*n)++;
}
else if(i>pp[--cnt])
{
cnt++;
pp[cnt++]=i;
(*n)++;
}
}
}
}
}
int main()
{
int aaa[100]={
0};
int ss=0;
fun(512,aaa,&ss);
for(int i=0;i<ss;i++)
{
cout<<aaa[i]<<endl;
}
return 0;
}
边栏推荐
- 透过JVM-SANDBOX源码,了解字节码增强技术原理
- Why is the probability of pod increasing after IPtable
- vim映射命令
- The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
- The difference between bagging and boosting in machine learning
- Flink学习8:数据的一致性
- 分布式系统:what、why、how
- SDP中的SPA
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- 如何有效远程办公之我见 | 社区征文
猜你喜欢

02 ls 命令的具体实现

函数计算异步任务能力介绍 - 任务触发去重

EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?

Objective-C description method and type method

Unity 绘制弹球和台球的运动轨迹

SQL語句加强練習(MySQL8.0為例)

三年进账35.31亿,这个江西老表要IPO了

分布式系统:what、why、how

Understand the principle of bytecode enhancement technology through the jvm-sandbox source code

leetcode刷题:二叉树06(对称二叉树)
随机推荐
1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
Katalon使用script实现查询List大小
leetcode刷题:二叉树04(二叉树的层序遍历)
【webrtc】m98 ninja 构建和编译指令
函数计算异步任务能力介绍 - 任务触发去重
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
[book club issue 13] packaging format of video files
“软硬皆施”,助力建成新型云计算数据中心
Database SQL statement summary, continuous update
Interpretation of leveldb source code skiplist
Idea configuration 360zip open by default -- external tools
透过JVM-SANDBOX源码,了解字节码增强技术原理
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
2020 Bioinformatics | TransformerCPI
Unity 绘制弹球和台球的运动轨迹
Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
Pytest multi process / multi thread execution test case
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
Katalon framework tests web (XXI) to obtain element attribute assertions
PPt 教程,如何在 PowerPoint 中将演示文稿另存为 PDF 文件?