当前位置:网站首页>(指针)编写函数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;
}
边栏推荐
- mysql数据库的存储
- leetcode刷题:二叉树06(对称二叉树)
- SQL语句加强练习(MySQL8.0为例)
- Katalon框架测试web(二十六)自动发邮件
- Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
- 思考的小记录
- The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
- My opinion on how to effectively telecommute | community essay solicitation
- Flink学习7:应用程序结构
- Wechat official account web page authorization
猜你喜欢
软件测试是干什么的 发现缺陷错误,提高软件的质量
Flink学习8:数据的一致性
10 reasons for not choosing to use free virtual hosts
02 specific implementation of LS command
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
【微服务|openfeign】@FeignClient详解
透过JVM-SANDBOX源码,了解字节码增强技术原理
02 ls 命令的具体实现
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Select sorting and bubble sorting template
随机推荐
Distributed system: what, why, how
Perf simple process for multithreaded profile
Go 语言入门很简单:Go 实现凯撒密码
VIM mapping command
Activiti7 task service - process variables (setvariable and setvariablelocal)
JDBC 进阶
Pointer array and array pointer
pytest多进程/多线程执行测试用例
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.
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
思考的小记录
Objective-C description method and type method
Small record of thinking
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?
Epidemic strikes -- Thinking about telecommuting | community essay solicitation
leetcode刷题:二叉树07(二叉树的最大深度)
*. No main manifest attribute in jar
JS实现文字滚动 跑马灯效果
Support the first triggered go ticker
How was my life in 2021