主要保理程序给我带来问题 [英] prime factoring progam giving me problems

查看:94
本文介绍了主要保理程序给我带来问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要输出输入的整数的素数。我是C ++的新手,但是我和我的伙伴一起编写了这个程序,并且在编译时,这就是它所做的一切。我很确定它会在for循环中丢失,或者至少在我迷失的地方。

I need to print out the prime numbers of an integer entered in. I am new to C++ but wrote this program with my partner and while it compiles, that''s about all it does. I''m pretty sure it gets lost in the for loop, or atleast that''s where I get lost.

展开 | 选择 | Wrap | 行号

推荐答案


我需要打印出来输入的整数的素数。我是C ++的新手,但是我和我的伙伴一起编写了这个程序,当它编译时,就是它所做的一切。我很确定它会在for循环中丢失,或者至少在我迷失的地方。
I need to print out the prime numbers of an integer entered in. I am new to C++ but wrote this program with my partner and while it compiles, that''s about all it does. I''m pretty sure it gets lost in the for loop, or atleast that''s where I get lost.
展开 | 选择 | Wrap | 行号


好吧,我有两件事要提。


首先关闭,它看起来不像你设置在素数。当您需要使用不同的变量时,看起来您正试图使用​​for循环的迭代器来计算输入数。 (你计算2,3,4,5,6,......你需要考虑2,3,5,7,11,......)


i我认为您还需要某种数据结构来保存您迄今为止已经找到的因素。你需要记录你可以除以2,然后是3和5的次数。 。 。等。
well, i have two things to mention.

first off, it doesnt look like youre set up to count in primes. it looks like youre trying to use the iterator for your for loop to factor the input number when you need to use a different variable. (youre counting by 2,3,4,5,6, . . . and you need to be factoring by 2,3,5,7,11, . . . )

i think you also need some sort of data structure to hold the factors youve already found so far too. you need to keep track of how many times you can divide by two, and then three, and five . . . etc.



你只在''else''语句中增加n,这意味着如果你输入''if''部分,n在循环中保持不变(一旦它变得均匀,它就会卡住)。无论如何,您都可以增加n,并单独打印出每个因子。
You only increment n in the ''else'' statement, which means that if you enter the ''if'' portion, n stays the same through the loop (as soon as it''s even, it gets stuck). You could just increment n no matter what, and print out each factor individually.




我在想这个,你的意思是在for循环中增加它?我不确定如何将每个因素打印出来。



I was thinking of this, you mean increment it in the for loop? I''m not sure how i would get each factor to print out then.


这篇关于主要保理程序给我带来问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆