当前位置:网站首页>(指针)编写函数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;
}
边栏推荐
- 三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
- Mindmanager2022 efficient and easy to use office mind map MindManager
- Two commonly used graphics can easily realize data display
- Katalon uses script to query list size
- Activiti7 task service - process variables (setvariable and setvariablelocal)
- 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.
- 如何有效远程办公之我见 | 社区征文
- 【微服务|openfeign】@FeignClient详解
- vim正确加区间注释
- 1289_FreeRTOS中vTaskSuspend()接口实现分析
猜你喜欢
【罗技】m720
Idea configuration 360zip open by default -- external tools
ctf-pikachu-XSS
Distributed system: what, why, how
User defined path and file name of Baidu editor in laravel admin
Brief explanation of depth first search (with basic questions)
Getting started with the go language is simple: go implements the Caesar password
'2'&gt;' 10'==true? How does JS perform implicit type conversion?
Storage of MySQL database
毕业设计:设计秒杀电商系统
随机推荐
Detailed explanation of PPTC self recovery fuse
leetcode刷题:二叉树04(二叉树的层序遍历)
Objective-C description method and type method
程序员远程办公喜忧参半| 社区征文
leetcode刷题:二叉树08(N叉树的最大深度)
'2'&gt;' 10'==true? How does JS perform implicit type conversion?
Reduce function under functools
2020 Bioinformatics | TransformerCPI
pytest多进程/多线程执行测试用例
[Yugong series] go teaching course 002 go language environment installation in July 2022
Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
Objective-C string class, array class
02 specific implementation of LS command
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
[book club issue 13] multimedia processing tool ffmpeg tool set
Katalon中控件的参数化
Katalon framework test web (XXVI) automatic email
Objective C attribute keyword
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?
如何远程办公更有效率 | 社区征文