输出素数 [英] Outputting Prime Numbers

查看:106
本文介绍了输出素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,

我需要一个程序来输入一个数字,测试它是不是素数,如果是素数则输出它,如果不是则输出下一个素数。

到目前为止,我必须输入部分,函数和素数测试,这样如果它是素数就可以工作,但我不知道如何输出下一个素数。

任何帮助都会非常感激。

Hey All,
I need a program to input a number, test if it is a prime number or not and then output it if it is prime or output the next prime number if it is not.
So far I have to input section, the function and the prime number test so it works if it is prime but I can''t figure out how to output the next prime number.
Any help would be much appreciated.

推荐答案

您好,

下一个素数你不能只是从非素数循环素数测试函数,直到找到素数,然后返回。如果那不起作用,你的功能如何工作?
Hello,
for the next prime number can''t you just loop the prime number testing function from the non-prime until it finds a prime number and then return that. If that doesn''t work, how does your function work then?


我不知道如何循环一个函数。我只是把它放在一个for循环中,就像任何其他值一样吗?
I wasn''t sure how to loop a function. Do I just put it in a for loop like any other value?


你好朋友

我红了你的问题。

让一个数字不是素数...

然后我们去一个循环语句形成一个到+ 100 ......

i我确定在该范围之间必须有一个素数....
hi friend
i red you question .
let a be the number is not a prime ...
then we go for a looping statement form a to a+100...
i am sure that there must be a prime in between that range....


这篇关于输出素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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