The sequence goes as this : If the last integer n is odd, the next integer is 2n
ID: 3640818 • Letter: T
Question
The sequence goes as this : If the last integer n is odd, the next integer is 2n – 1.If the last integer n is even, the next integer is 2n + 1.
The sequence will keep generating integers until it comes across a prime number. Example sequences are below :
6 13.
12 25 49 97.
10 21 41.
5.
You will implement two functions : one to determine if a given number is prime or not; and another to generate the sequence with the rules given above. Whole sequence must be printed to the screen, along with the number of integers in the sequence.
Use functions properly. If a function is supposed to do something, it all has to happen inside the function (all calculations/loops/controls must be done within the function). Also, do not do anything other than the purpose of the function (anything unrelated to the function must stay outside the function).
You can print the numbers inside the sequence-generating function (since you can't return more than 1 number). The number of integers in the sequence must be printed outside the function.
Explanation / Answer
PS: Please rate the answer #include int primeOrNot(int i); int generateSequence(int i); int primeOrNot(int i){ int a = 2; for (a = 2; aRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.