error in printing prime number from 2 to n using for loop
Print all Primes
hello @dasvishal60
check now->
use outer loop to iteratr from [2…n]
and inner loop to count number factors.
if no of factors==2 (1 and the number itself) its a prime otherwise not
its not working!!! wrong output
check tthis->
this one is hard any alternate solution for this??
no its not hard,u just need to know how to find whether a number is prime or not.
prime numbers are number with exaclty two factors ie (1 and the number itself)
for example ->
5 ( 1 and 5 are the only factors)
7 ( 1 and 7 are the only factors)
6 ( 1,2,3,6 more than 2 factors so its not a prime)
so all we need to do is we need to run a loop from 1 to that number and count total number of factors .
if it comes 2 then it is prime otherwise not.
same thing we are doing in the above solution.
outer loop is to iterate from 2 to N
and inner loop is counting factors of each number . if factors is 2 then its prime otherwise not prime
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.