C Programming Tutorial 73 - Check if Number is Prime (Counting Prime Numbers Part 2)

  Рет қаралды 43,241

Caleb Curry

Caleb Curry

Күн бұрын

Start your software dev career - calcur.tech/de... 💯 FREE Courses (100+ hours) - calcur.tech/al...
🐍 Python Course - calcur.tech/py...
✅ Data Structures & Algorithms - calcur.tech/ds...
~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
✉️ Newsletter - calcur.tech/ne...
📸 Instagram - / calebcurry
🐦 Twitter - / calebcurry
🔗 LinkedIn - / calebcurry
▶️ Subscribe - calcur.tech/sub...
👨🏻‍🎓 Courses - www.codebreakt...
~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
↪ My Amazon Store - www.amazon.com...
🅿 Patreon - calcur.tech/pat...
🅖 GitHub Sponsors - github.com/spo...
Ⓟ Paypal - paypal.me/calcur
🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
📈 Buy Bitcoin - calcur.tech/cr...
Reserve the Ruby Steel crypto rewards card and get a $25 bonus (use affiliate code "Caleb") - calcur.tech/cr...

Пікірлер: 44
@filip6472
@filip6472 2 жыл бұрын
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
@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.
@burayaneyazsambilemedim8442
@burayaneyazsambilemedim8442 Жыл бұрын
Kardesim selaminaleykum, cs50'den bahsediyorsun sanirim. Nasil gidiyor bitirdin mi?
@MoneyModernized
@MoneyModernized Ай бұрын
currently doing one for my lab.
@kyleeames8229
@kyleeames8229 4 жыл бұрын
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.
@cheerios623
@cheerios623 4 жыл бұрын
You actually only need to check up to sqrt(n)!
@7s9n
@7s9n 3 жыл бұрын
@@cheerios623 yeah 💛
@janlangeloh3269
@janlangeloh3269 3 жыл бұрын
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. 👍👌🖖
@adventdanielkarabo9558
@adventdanielkarabo9558 3 жыл бұрын
i like how you not so tense on your videos appreciated maa`n
@PunmasterSTP
@PunmasterSTP 3 жыл бұрын
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
@joocaarjucfe5675 Жыл бұрын
It's good if it's small numbers but for greater numbers they're more efficient algorithm to find prime numbers
@UnusRamadan-db2vg
@UnusRamadan-db2vg 2 ай бұрын
That's very helpful
@NymaMargaret
@NymaMargaret Жыл бұрын
You're such an amazing teacher
@lsbigshot
@lsbigshot Жыл бұрын
Thanks, this video really made it simple to understand!
@tv..6531
@tv..6531 4 жыл бұрын
kzbin.info/www/bejne/ZnKln4KVjNSYrqc 를 이용하여 1부터 1,000까지 사이에 있는 소수의 개수(counting prime numbers)를 구하는 영상 입니다.
@abhishekrbhat8919
@abhishekrbhat8919 3 жыл бұрын
Thank you very much!
@amishisharma7100
@amishisharma7100 2 жыл бұрын
bro you love pizza more than anythingggg lolololo
@josephinehannah103
@josephinehannah103 3 жыл бұрын
Omg thank you so much!!
@gamer-ox7tg
@gamer-ox7tg 2 жыл бұрын
Thanks man
@gamingwithjoshua1261
@gamingwithjoshua1261 3 жыл бұрын
the best teacher
@dantecastillodelasfuentes1026
@dantecastillodelasfuentes1026 5 жыл бұрын
you´re the best
@ilovecode2256
@ilovecode2256 4 жыл бұрын
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?
@amir3515
@amir3515 4 жыл бұрын
yes
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
There are lot ways to do it, man
@allrounderzcreations
@allrounderzcreations 3 жыл бұрын
Check here kzbin.info/www/bejne/e6rPYmqNnK1lZ5o Subscribe if you like the code
@izanyibukayvette381
@izanyibukayvette381 3 жыл бұрын
@@tiagodmota5840 but how me too if input is 2 then the output will look like 2 is not prime number
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
@@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
@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
@yeetyeetyeet1967 Жыл бұрын
you need a ; after i
@capnnemo5330
@capnnemo5330 3 жыл бұрын
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(" "); }
@PunmasterSTP
@PunmasterSTP 3 жыл бұрын
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").
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
-7 is a prime number?
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
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)."
@londonsystem6622
@londonsystem6622 4 жыл бұрын
The Best
@narayanfadte5652
@narayanfadte5652 7 ай бұрын
2?
@Zen-lz1hc
@Zen-lz1hc Жыл бұрын
LIKE :) Great video thanks You!
@adefolasayogboyega-adejuwo7285
@adefolasayogboyega-adejuwo7285 3 жыл бұрын
please can you code it
@jadoaesra3011
@jadoaesra3011 3 жыл бұрын
I DID IT!!!!
@paradise618
@paradise618 3 жыл бұрын
input=1 Result 1 is a prime number :(
@chasemedsker
@chasemedsker 2 жыл бұрын
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
@GaryIV Жыл бұрын
bool isPrime(n) { for(let x=2; x
@GaryIV
@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
@-keios8170
@-keios8170 11 ай бұрын
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
The Prime Number Race (with 3Blue1Brown) - Numberphile
20:29
Numberphile
Рет қаралды 389 М.
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 7 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 10 МЛН
C Programming Tutorial 72 - Counting Prime Numbers (Part 1)
9:58
L3. Check if a Number if Prime or not | Maths Playlist
7:10
take U forward
Рет қаралды 35 М.
Check If A Number Is Prime | C Programming Example
11:57
Portfolio Courses
Рет қаралды 12 М.
Find Prime Numbers In Java - Full Walkthrough with Source
13:17
Coding with John
Рет қаралды 36 М.
Special Programs in C − Check If The Number Is Prime Number
10:26
Neso Academy
Рет қаралды 139 М.
Problem #38 Is Prime Number
12:00
Programming Advices
Рет қаралды 59 М.
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 7 МЛН