As soon as you said Modulus and remainder is 0 for prime I knew how to code it.Thanks again for the tutorials they actually taught C better than other methods I tried.
@semihazah0352 Жыл бұрын
Finally, a video that has helped me complete the prime number loop for my lab. So many videos left me lost and confused. This is so much simpler when talked about at the simplest level.
Excellent tutorials. You only need to go up to n/2 to determine whether a number is prime. Moreover, if you store all the prime numbers identified up to n in an array, these can be tested up the largest before going on to consecutive integers larger than the largest prime as in the range 2 to the largest prime number identified up to n/2 at least one prime factor, if any factor will exist.
@cheerios6234 жыл бұрын
You actually only need to check up to sqrt(n)!
@7s9n3 жыл бұрын
@@cheerios623 yeah 💛
@janlangeloh32693 жыл бұрын
Yes because if it is not divisible by any number smaller than the square root of n there could be no one higher. Look if divide 21 by 3 you get the result 7. 7 is higher than sqrt(21), but still a divider. On the other hand side you alswase need to have a num smaller than sqrt(n) to allow this. Let's do 16 instead: 2 and 8 try to get closer: 4 and 4 there could not be a higher num because if there would the other pair had to be smaller than 4. 👍👌🖖
@adventdanielkarabo95583 жыл бұрын
i like how you not so tense on your videos appreciated maa`n
@PunmasterSTP3 жыл бұрын
Check if a number is prime? More like watch these videos for a good time! Thanks again for making and uploading all this amazing content.
@joocaarjucfe5675 Жыл бұрын
It's good if it's small numbers but for greater numbers they're more efficient algorithm to find prime numbers
@UnusRamadan-db2vg2 ай бұрын
That's very helpful
@NymaMargaret Жыл бұрын
You're such an amazing teacher
@lsbigshot Жыл бұрын
Thanks, this video really made it simple to understand!
@tv..65314 жыл бұрын
kzbin.info/www/bejne/ZnKln4KVjNSYrqc 를 이용하여 1부터 1,000까지 사이에 있는 소수의 개수(counting prime numbers)를 구하는 영상 입니다.
@abhishekrbhat89193 жыл бұрын
Thank you very much!
@amishisharma71002 жыл бұрын
bro you love pizza more than anythingggg lolololo
@josephinehannah1033 жыл бұрын
Omg thank you so much!!
@gamer-ox7tg2 жыл бұрын
Thanks man
@gamingwithjoshua12613 жыл бұрын
the best teacher
@dantecastillodelasfuentes10265 жыл бұрын
you´re the best
@ilovecode22564 жыл бұрын
What if the input here is 2, which should be a primenumber. The program would mark it as not prime since 2%2=0. Is there a way of implementation without an additional if statement, that explicitly checks if the input is 2?
@amir35154 жыл бұрын
yes
@tiagodmota58403 жыл бұрын
There are lot ways to do it, man
@allrounderzcreations3 жыл бұрын
Check here kzbin.info/www/bejne/e6rPYmqNnK1lZ5o Subscribe if you like the code
@izanyibukayvette3813 жыл бұрын
@@tiagodmota5840 but how me too if input is 2 then the output will look like 2 is not prime number
@tiagodmota58403 жыл бұрын
@@izanyibukayvette381 There should be a way to do it mathematically, as we're not mathematicians use an if statement. I said that there's a way because computer scientists work a lot when the subject is prime numbers, research for an algorithm that is 100% solid mathematically
@SketchupGuru Жыл бұрын
hi guys, what is wrong with my code? #include #include int main() { int input, i; printf("enter a number:"); scanf("%d", &input); for(int i=2; i
@yeetyeetyeet1967 Жыл бұрын
you need a ; after i
@capnnemo53303 жыл бұрын
Hey everyone, I tried to code this little project myself but only the first number's check is correct can you help me with the problem? the ./a.out file is below: 5 is a prime number 4 is not a prime number 3 is not a prime number 2 is not a prime number 1 is not a prime number #include int main() { int d=0; for(int i=4; i>0;i--) { for(int k=i;k>0; k--) { if( 0 == i % k) { d=d+1; } else if( 0 != i%k) { d=d; } } if(d==2) { printf("%i is a prime number ",i); } else if(d != 2) { printf("%i is not a prime number",i); } printf(" "); }
@PunmasterSTP3 жыл бұрын
I think you need to reset d = 0 at the beginning of each iteration of the outer loop, like this: ... for(int i = 4; i > 0; i--) { d = 0; for(int k = i; k > 0; k--) { ... If you don't reset d, then it will just keep increasing for each number. Therefore it would never be equal to 2 again, and every number (except for possibly the first number) would seem not prime (i.e. "composite").
@tiagodmota58403 жыл бұрын
-7 is a prime number?
@tiagodmota58403 жыл бұрын
I googled and found this: "Prime numbers are a mathematical concept that describes POSITIVE whole numbers that can only be divided evenly by two other whole numbers (or factors)."
@londonsystem66224 жыл бұрын
The Best
@narayanfadte56527 ай бұрын
2?
@Zen-lz1hc Жыл бұрын
LIKE :) Great video thanks You!
@adefolasayogboyega-adejuwo72853 жыл бұрын
please can you code it
@jadoaesra30113 жыл бұрын
I DID IT!!!!
@paradise6183 жыл бұрын
input=1 Result 1 is a prime number :(
@chasemedsker2 жыл бұрын
input should always be above 1 by default considering its already mathematically proven to not be prime, I understand concern tho, but result is due to 1 being only other number requiring diff algo to determine whether prime or not--confused me too
@GaryIV Жыл бұрын
bool isPrime(n) { for(let x=2; x
@GaryIV Жыл бұрын
This is why braces are the dumbest way to organize code. Here's the same code in Python. def isPrime(n): for x in range(2,int(sqrt(n)+1)): if not(n%x): return False return True
@-keios817011 ай бұрын
I'm clinging, but braces are not used to organize code. It is simply a grouping instruction, it collects several instructions into one, which can be then used at the same time, for example, in a conditional statement. For example in java: public static boolean isPrime(int n){ if( n