How to print prime numbers from 1 to 10

Hi!

How can we print prime numbers from 1 to 10 using while loop

Thanks

There are multiple threads on this already. You can easily search the forum to find them.

https://forum.uipath.com/search?q=prime%20numbers

@404_Error

One of the methods. Gives array of prime numbers

primeNumbers = Enumerable.Range(1, 10).Where(Function(n) (n > 1) AndAlso Enumerable.Range(2, n-1).Count(Function(m) n mod m = 0) = 1).ToArray

Cheers

1 Like

Hi @404_Error

Do this:

  1. Initialise num=2 & i=1
  2. Take a while & put condition num<=10
  3. Inside while, reset i=2
  4. Inside the while, add another while & set condition i<num.
  5. Inside this inner while, add if with condition - num mod i =0.
  6. If true, do num = num+1 & put break activity.
  7. If false, do i = i+1
  8. After inner while, add if condition.
  9. Condition for if - i = num. if true, write the number, as it is prime.
  10. In the end, do num = num+1 (near outer while ending)

Hope this helps,
Best Regards.

1 Like

Hi,

i followed all the steps

i mentioned num<10. but it is still giving me the 11 number.

Thanks,

@404_Error

Try num<=10

Best Regards.

@404_Error

Did you try the above code in assign

cheers

Hi,

Still it is giving me the 11

Hi!

I need it by using while condition.

If we managed to use ne while condition it could be more helpful

Thanks,

@404_Error

Please check this

cheers

@404_Error

As per our discussion yesterday, I’m attaching the complete workflow. Please let us know if you find any further difficulty.

PrimeNumberGeneration.zip (144.2 KB)

Best Regards.

2 Likes

Thank you so much for your help

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.