编写c语言程序 在控制台输出,求大神解答,要完整代码!编写一个C#控制台应用程序,要求从键盘输入一个正整数n,然后输出n的所有因子...

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

chunhai8395

推荐于 2017.12.16

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:53%    等级:12

已帮助:38018人

public int[] GetFactors(int n){

int Count = 0;

int[] temp = new int[n];

for(int i = 1; i < n; i++){

if (n % i == 0) {

temp [Count] = i;

Count++;

}

}

int[] OutFactors = new int[Count];

for (int i = 0; i < OutFactors.Length; i++) {

OutFactors [i] = temp [i];

}

return OutFactors;

//by NWinterSS

}

使用的时候,创建一个int[]然后让它等于这个函数就可以调出了。没有优化,数比较大的话比较耗资源,凑活用吧😊。

求采纳。

P.S.我是平时用U3D做这些所以其它功能还得自己稍微链接一下。追问: 我是用Visual studio2010的,然后我是渣渣,复制进去有错误,越改越多错,想哭了!

追答:估计就是调用时有问题吧。

我没用过VS,都是在Mac上做前端所以大概没法继续帮你太多。

试试:

public void GetFactors(int n, out int[] Factors){

Debug.Log ("Start");

int Count = 0;

int[] temp = new int[n];

for(int i = 1; i < n; i++){

if (n % i == 0) {

temp [Count] = i;

Count++;

}

}

int[] OutFactors = new int[Count];

for (int i = 0; i < OutFactors.Length; i++) {

Debug.Log (temp [i]);

OutFactors [i] = temp [i];

}

Factors = OutFactors;

Debug.Log ("Ended, with total of "+Count+" Factors");

}

在某个地方调用这个函数,会在Console里输出所有的数。

然后在后面两个参数分别为n是一个整数,你要找的那个,factors是一个int[]。

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值