0
Finding prime numbers in given fibonacci series
This is a c++ program that I need to find prime numbers of fibonacci series. the question says that after you enter the n ( the number of fibonacci series ) the program has to extract the prime numbers from it, and then, if the sum of those prime numbers is an odd number, it has to show 'A' and if it's even, it should show 'D'. The problem is i know how to find both fibonacci series and prime numbers, but i can't put them together. And i need to keep the code as simple as possible Can someone help me in this?
4 odpowiedzi
+ 6
Kimia , before we can help you, you should show us your attempt first. if you have not done a try by yourself upto now, please do so. Put your code in playground and link it here. Thanks!
+ 4
Kimia , what you can do is: (for the moment it's better not to "merge" these two calculations (fibonacci and prime) better try it this way):
▪︎ use one code that contains both calculstions
▪︎ run the code for the fibonacci series first
▪︎ store the resulting numbers in an array or a list
▪︎ after the fibonacci numbers are done, start processing the prime numbers
▪︎ use a loop to iterate through the sequence (array or list) and check each member if it is prime of not
▪︎ print the resulting numbers
that's all! - try to pug it together. if you get stuck, put your code in playground and link it here. thanks!
AND PLEASE: do not use such cryptic variable names. use meaningful identifiers. being lazy here, does not really save time. thanks
+ 1
Lothar thank you so much! I'll try my best
0
Lothar
So this is what i wrote for fibonacci
https://code.sololearn.com/cIMR29J27wT6/?ref=app
And this one is for prime number ( but is shows how many prime numbers are in the given number )
https://code.sololearn.com/cXiww1rV83qD/?ref=app