r/code • u/Anonylost • Jun 03 '21
Urgent Code
Does anyone know how to write a code preferably in c++ to find the index of an element of a list where the sum of prime numbers on the right equal the left? If you do kindly help I'm still a newbie it would be highly appreciated
0
Upvotes
3
u/anavid7 Jun 03 '21
Not sure what you question is yet? What is in your array? Is it the list of primes? Are you saying addition of the index to the prime? Would you mind re-asking your question?
9
u/angryrancor Boss Jun 03 '21
this sounds like homework help. because of that, I'll give you some general tips, but not a solution, since using this sub for "cheating" is not allowed.
What you want is:
two variables to accumulate your totals,
int sumLeftandint sumRight. You will use these to compare the total of primes, at the end.a
forloop, that movesifrom0tosize(arrayLeft)In the for loop:
if isPrime(arrayLeft[i]): sumLeft += arrayLeft[i]. Do the same for the right array, and `sumRight`. You'll need to google to figure outisPrimeyourself, that part is easy.after the
forloop,printf(str(sumLeft == sumRight)), if you want to print the result. Or do whatever you want with the result ofsumLeft == sumRight, at that point.Note: Like I said, cheating on homework is not allowed, but we can give hints. What is explicitly not allowed in this sub, is giving a solution to an obvious homework assignment, in full.