C Programming Tutorial 74 - Algorithm to Check for Prime (Counting Prime Numbers Part 3)

  Рет қаралды 18,278

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...

Пікірлер: 25
@nadpro16
@nadpro16 4 жыл бұрын
If you run into undefined reference to `sqrt'add -lm to the end of the compile command. examp: gcc -lm
@ColbusMaximus
@ColbusMaximus 2 жыл бұрын
this solved my issue, but why?
@JTCano42
@JTCano42 4 жыл бұрын
Thanks a lot, Caleb! Great tutorial.
@ralph_d_youtuber8298
@ralph_d_youtuber8298 Жыл бұрын
I'll say that discrete math was really stresfull but it helps when doing some types of programming assumptions, cuz like u can mentally do the proof that yap its mathmatecally valid to do this. And ya its to loop to the sqrt of the number you want to find
@ashokkumar845
@ashokkumar845 3 жыл бұрын
Hi caleb, in for loop at end of loop it is going to divide by 2 and based on this every number will be decide either prime or not, since we are not breaking loop. For example take 9, at end using for loop it will be divided by 2. So it should be prime as per coding. Bt still it is saying 9 is not prime... need your explination on this
@diegocassinera
@diegocassinera 2 жыл бұрын
Wow you continue working after you know the answer
@kaelarellano4540
@kaelarellano4540 2 жыл бұрын
how long does it take for you to create a program like this? it's just i' m a bit curious since you're like doing things like this like it was nothing
@PunmasterSTP
@PunmasterSTP 3 жыл бұрын
Prime number? More like "I wonder...how many more amazing videos you have in store for us!"
@viviennezhang5326
@viviennezhang5326 2 жыл бұрын
Why is isPrime an int when initialized? Shouldn't it be bool?
@victorgodwin3027
@victorgodwin3027 2 жыл бұрын
That's typecasting, it was typecasted to a bool
@viviennezhang5326
@viviennezhang5326 2 жыл бұрын
@@victorgodwin3027 I meant line 7, when "isPrime" was initialized and set to "true", the type was "int" instead of "bool". I don't think it's typecasting here.
@victorgodwin3027
@victorgodwin3027 2 жыл бұрын
The variable isPrime of type int was stored as a type bool, either ways the meaning is the same. (Typecasting)
@pradyumnasrivastava2319
@pradyumnasrivastava2319 4 жыл бұрын
It works but when I took an extremely large number it said its prime even though it had a 0 at the end
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
There are more details about the primitive data types... This error has to do with the interval of numbers that int supports, because it has just 4 bytes, and if you calculate 2^32 bits you'll see the largest number that can be stored in an int data type.
@bibfocal
@bibfocal 4 жыл бұрын
The sqrt() method is incorrect. Attempt 121 as input for both versions, with and without sqrt(). With sqrt() it is stated as prime, without it is stated as not prime. 121 is not prime because it can be divided by more than two whole numbers, 1, 11, 121. A prime number can only be divided by itself and 1.
@codebreakthrough
@codebreakthrough 4 жыл бұрын
😢 sorry if anything’s incorrect. It happens from time to time
@bibfocal
@bibfocal 4 жыл бұрын
@@codebreakthrough It's all good, man. Keep up the great work your doing. I see you are teaching Python now. I do love the language, and it has so many more tools available than C. Great for getting some quick and dirty work done to keep the bosses happy.
@christopherindrawan1316
@christopherindrawan1316 4 жыл бұрын
i changed the boolean name to notPrime and didnt assign a value to it so it will be false by default. and for the if statement, everytime the input % i is equal to 0, it will triggers the notPrime value to be true and print a statement that it is not a prime number. prime number will never triggers the notPrime value and it means the number is prime. This solves ur problem, i tried 121 and it results a not prime number. and everything else works fine.
@tiagodmota5840
@tiagodmota5840 3 жыл бұрын
This code of mine doesn't have that error: #include #include #include int main(void) { int numInput = 0; bool isPrime = true; printf("Enter a number and see if it is prime or not: "); scanf("%d", &numInput); if (numInput < 2) { isPrime = false; }else { for (int i = sqrt(numInput); i > 1 && isPrime == true; i--) { isPrime = ((numInput % i) != (0)) ? (true) : (false); } } printf("%d is prime? Answer: %d (0: No. 1: Yes.) ", numInput, isPrime); return 0; }
@londonsystem6622
@londonsystem6622 4 жыл бұрын
The Best
@iromakoootieno2713
@iromakoootieno2713 Жыл бұрын
clever
@joshuahao6991
@joshuahao6991 3 жыл бұрын
can some one copy the code thanks
@z-root8955
@z-root8955 3 жыл бұрын
why don't you just check if the input % 2 == 0 then print is prime otherwise print not prime I might be wrong but I think you can do it just in few lines
@ronpipes1988
@ronpipes1988 2 жыл бұрын
If you watch a couple of videos back he states that there is probably an easier way but that he's going to do it a more difficult way.
Prime Numbers & RSA Encryption Algorithm - Computerphile
15:06
Computerphile
Рет қаралды 176 М.
1 сквиш тебе или 2 другому? 😌 #шортс #виола
00:36
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 29 МЛН
Worst flight ever
00:55
Adam W
Рет қаралды 56 МЛН
A Beautiful Algorithm for the Primes
9:13
Aaron Learns
Рет қаралды 101 М.
Problem #38 Is Prime Number
12:00
Programming Advices
Рет қаралды 59 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 840 М.
Coding Was Hard Until I Learned THESE 5 Things!
7:40
Pooja Dutt
Рет қаралды 1 МЛН
How Square Roots Can Help You Check Prime Numbers
9:16
Domotro from Combo Class
Рет қаралды 14 М.
My 2 Year Journey of Learning C, in 9 minutes
8:42
VoxelRifts (PixelRifts)
Рет қаралды 623 М.
C Programming Tutorial 72 - Counting Prime Numbers (Part 1)
9:58
Dijkstra's Hidden Prime Finding Algorithm
15:48
b001
Рет қаралды 165 М.