Click here to Skip to main content
14,270,343 members
Rate this:
Please Sign up or sign in to vote.
See more:
def generate_two_primes(a, b):
l = range(a, b + 1)
primes = []
count = 0

while (count < 2):
test = rd.choice(l)
if is_prime(test) is True:
primes.append(test)
count += 1
l.remove(test)

return primes[0], primes[1]

What I have tried:

I have tried in C but im not getting it.
Posted
Updated 3-Jul-19 22:41pm
Comments
CPallini 4-Jul-19 4:35am
   
Show us your C code, wecould help you on that.
By the way: it would be better to rewrite it from scratch in C programming language.
susmitharaj 4-Jul-19 4:42am
   
include <stdio.h>

int main()
{
printf(" \generate two primes(a, b):
l = range(a, b + 1)
primes = []
count = 0\n\");
return 0;
}
Stefan_Lang 4-Jul-19 7:46am
   
This is not valid C code. You should learn C before trying to convert a program from another language.
F-ES Sitecore 4-Jul-19 5:04am
   
I don't think C has functions like "is_prime", you'll need to code that up yourself. Rather than googling your homework question, finding the answer in python and getting other people to translate that to the language your homework is on, just code the thing from scratch in C otherwise you learn nothing. We don't mind answering specific questions when you're stuck on something but we're not here to do your homework for you.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
   
Comments
susmitharaj 4-Jul-19 4:42am
   
include <stdio.h>

int main()
{
printf(" \generate two primes(a, b):
l = range(a, b + 1)
primes = []
count = 0\n\");
return 0;
}

I got this...
OriginalGriff 4-Jul-19 4:52am
   
So ... which of the two languages do you not know, and which do you understand well?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100