当前位置:网站首页>(指针)编写函数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;
}
边栏推荐
- leetcode刷题:二叉树07(二叉树的最大深度)
- mysql数据库的存储
- STM32外接DHT11显示温湿度
- SQL語句加强練習(MySQL8.0為例)
- Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
- Penetration practice - sqlserver empowerment
- 疫情来袭--远程办公之思考|社区征文
- leetcode刷题:二叉树05(翻转二叉树)
- 指针数组和数组指针
- Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
猜你喜欢
SQL語句加强練習(MySQL8.0為例)
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
【微服务|openfeign】@FeignClient详解
深度优先搜索简要讲解(附带基础题)
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
Penetration practice - sqlserver empowerment
用于TCP协议交互的TCPClientDemo
The maximum expiration time of client secret in azure ad application registration is modified to 2 years
pytest多进程/多线程执行测试用例
透过JVM-SANDBOX源码,了解字节码增强技术原理
随机推荐
Katalon框架测试web(二十一)获取元素属性断言
STM32外接DHT11显示温湿度
[paddleseg source code reading] paddleseg custom data class
[paddleseg source code reading] normalize operation of paddleseg transform
Rhcsa-- day one
Introduction to asynchronous task capability of function calculation - task trigger de duplication
如何远程办公更有效率 | 社区征文
2022-07-03: there are 0 and 1 in the array. Be sure to flip an interval. Flip: 0 becomes 1, 1 becomes 0. What is the maximum number of 1 after turning? From little red book. 3.13 written examination.
02 ls 命令的具体实现
JDBC advanced
How to dynamically cache components in Vue multi-level route nesting
Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
疫情来袭--远程办公之思考|社区征文
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
Katalon framework test web (XXVI) automatic email
【webrtc】m98 ninja 构建和编译指令
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Objective-C member variable permissions
Illustrated network: what is the hot backup router protocol HSRP?