[家庭作业]如何检查数字是否为素数 [英] [HOMEWORK] How to check if a number is prime or not
本文介绍了[家庭作业]如何检查数字是否为素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,下面的代码是我到目前为止所得到的。我希望循环检查数字为2-10000并停止在10000并从2开始。我有一个问题如何将函数转换为循环。
Hello, the code below is what I got so far. I would like the loop to check numbers to 2-10000 and stop at 10000 and begins at 2. The question I have how do you make a function into a loop for.
展开 | 选择 | Wrap | 行号
推荐答案
您的程序中已有for循环和函数调用。你在问什么?你想循环遍历2到10000之间的所有数字,但你已经这样做了。当它最终达到10000时,你希望它从10000循环回到2,这可以通过检查当前值是否>> 10000并且是否指定值2来重新开始来轻松完成。
如果您需要其他答案,您将不得不更详细地描述您的问题。
You have a for loop and a function call already in your program. What are you asking about? You want to loop through all the numbers between 2 and 10000, but you already do that. You want it to loop back from 10000 to 2 when it finally reaches 10000, that can be easily done by checking if the current value is >= 10000 and if it is assigning a value of 2 to start all over again.
If you need other answers you are going to have to describe your question in more detail.
展开 | 选择 | Wrap | 行号
您的程序中已有for循环和函数调用。你在问什么?你想循环遍历2到10000之间的所有数字,但你已经这样做了。当它最终达到10000时,你希望它从10000循环回到2,这可以通过检查当前值是否>> 10000并且是否指定值2来重新开始来轻松完成。
如果您需要其他答案,您将不得不更详细地描述您的问题。
You have a for loop and a function call already in your program. What are you asking about? You want to loop through all the numbers between 2 and 10000, but you already do that. You want it to loop back from 10000 to 2 when it finally reaches 10000, that can be easily done by checking if the current value is >= 10000 and if it is assigning a value of 2 to start all over again.
If you need other answers you are going to have to describe your question in more detail.
对不起,让我试着让它更清楚。我想在main中创建一个循环,循环从2到10000.循环将通过一个函数isPrime。 isPrime将检查一个数字是否为素数,如果是,则返回1,如果不是则返回0.
Sorry, let me try to make it more clear. I want to make a loop that is in main that loops from 2 to 10000. The loop will go through one function "isPrime". isPrime will check to see if a number is a prime or not and will return 1 if it is and if not return 0.
这篇关于[家庭作业]如何检查数字是否为素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文