以下作业题,请各位帮忙指点,因刚学c++,请各位老师在程序尽量多些注释说明。谢谢!
正整数n是素数,如果它只能由1和本身整除。
(1)写一个名为ISPrime的C++函数,它取正整数参数,如果参数为Prime,则返回true,否则返回false。假设参数大于1
(2)写一个C++函数,名为SUFFPrimes,取正整数参数n,并返回第一N素数的和。例如,SUFFPrimes(6)必须返回41,这是前6个素数的总和:
2+3+5+7+11+13=41。您必须使用在部分(1)中定义的ISPrime函数来定义函数SUFFPROMES。
原题:A positive integer number n is prime if it is divisible by ONLY 1 and
itself.
a. Write a C++ function named isPrime that takes a positive
integer argument and returns true if the argument is prime and returns
false otherwis。 Assume the argument is greater than 1.
b.Write a C++ function named sumOfPrimes that takes a positive integer
argument n and returns the sum of the first n prime numbers. For example,
sumOfPrimes(6) must return 41 , which is the sum of the first 6 prime numbers:
2+3+5+7+11+13 = 41. You must use the isPrime function you defined in part (a) to define the function sumOfPrimes.
哈士奇WWW
相关分类