Check If A Number Is Prime | C Programming Example

  Рет қаралды 12,465

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 28
@Klusio19
@Klusio19 2 жыл бұрын
And there we go! A long-awaited correct version of the previous program is here. Thank you for remembering my suggestion in previous video about prime numbers!
@Klusio19
@Klusio19 2 жыл бұрын
Also I have one question: what is that IDE you are using? Sometimes I can see in your videos, you are using that kind of IDE, and other times I can see you are using some kind of text ediotor and compiling in the terminal. What is that text editor?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@Klusio19 The text editor is Visual Studio Code. I've turned off a lot of features so they take up less screen space. The IDE I sometimes use is Xcode, where again I've turned off a lot of options to make it look that way.
@zoquevil4792
@zoquevil4792 2 жыл бұрын
Thank you for the details on gitub, very useful to re-work on it!!! I have a question for you sir: can you suggest something for the beginners about testing our program because something we run the program for two or tree values and don't know that we need to test anotherone just to see if the algorithm is enough correct? something like to anticipate the punsh as in the kung fu lol ... J'adore les petits details dans vos explications !!!😉 Thanks !
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
That's a really good question. :-) When testing out code, it's often a good idea to use "special cases" as inputs. There are different names for these special cases such as "boundary cases". But basically the idea is that if we have a program that is expected to change behaviour at a certain input, like x = 0, then good test cases would be x=-1, x=0, and x=1 because we are testing "the important part" where behaviour should change. Using test inputs like x=2, x=3, x=4 won't matter as much then testing "where the behaviour is expected to change". Maybe one day I can make a full video on this. :-)
@walidoulondon8107
@walidoulondon8107 Жыл бұрын
Best teacher ever ❤
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Awww, thank you! :-)
@ahmedabdulgawad4758
@ahmedabdulgawad4758 Жыл бұрын
duck debugger the AI designed by the staff of CS50 suggested to count from 2 to the square root of the number to improve the code speed I guess what do you think
@antoniomamic150
@antoniomamic150 Жыл бұрын
What a great tutorial! Thank you!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome Antonio, I’m glad you enjoyed it! :-)
@CoverDiaries
@CoverDiaries 7 ай бұрын
A question sir, if instead of bool is_prime , bool check_prime is used?
@UpsideDownSushi
@UpsideDownSushi Жыл бұрын
Amazing video, very easy to understand! I have one question though...I am a little confused about how the computer process the FOR loop. The FOR loop still executes the body even if the boolean expression is false? for (int i = 2; i < number; i++) if (number % 2 == 0) return false; in this case, if "number" was equal 2 then the loop should stop, right? Because "i" is not smaller than "number" but equal.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
If the boolean expression (condition) is false, the for loop body will not execute.
@King_Baldwin_IV_777
@King_Baldwin_IV_777 4 ай бұрын
Thanks man !
@justcurious1940
@justcurious1940 Жыл бұрын
Great explanation, I'm so dumb I was waiting u the whole video to add 2 as special case but then I realized that if the loop didn't run, the function will return true anyway : bool is_prime(int number){ if(number < 1) {printf("Error,number is not natural"); return false;} if(number == 1) return false; if(number == 2) return true; // not necessary for(int i = 2 ; i
@justcurious1940
@justcurious1940 Жыл бұрын
Also with the optimized version the loop does not run for the number : 3 🙃.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
That's exactly it, the special case takes care of itself. :-)
@cryptotechcoder
@cryptotechcoder Жыл бұрын
Is there a way to use recursion? Nice work!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Yes it's possible: www.sanfoundry.com/c-program-prime-number-using-recursion/. It won't really be a "pretty" solution in some sense, because you're essentially using a function parameter as a counter variable. We can translate any loop with a counter variable to a recursive function in this way, so that's why I say it's not "pretty" or "elegant", it's just sort of a "crude translation". But it will work. :-) Maybe I'll do a video on it, and a video on translating from a loop to recursion in general...
@flipzenpai3401
@flipzenpai3401 Жыл бұрын
Very understandable. Thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome Flip! :-)
@lucgagnon7169
@lucgagnon7169 7 ай бұрын
#include bool is_prime( int number ) { if ( number
@jomez2841
@jomez2841 Жыл бұрын
Don’t you only need to check up until the square root of n?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Yes, we can optimize it even more that way. :-)
@xxz4655
@xxz4655 2 жыл бұрын
Amazimg
@xxz4655
@xxz4655 2 жыл бұрын
It's art
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@xxz4655 Thank you! :-D
Advanced Integer Input Validation | C Programming Example
22:59
Portfolio Courses
Рет қаралды 12 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,2 МЛН
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 143 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 37 МЛН
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 106 МЛН
Special Programs in C − Check If The Number Is Prime Number
10:26
Neso Academy
Рет қаралды 139 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 262 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 796 М.
Calculate Factorial Using Recursion | C Programming Example
11:08
Portfolio Courses
Рет қаралды 6 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 314 М.
Check If A Number Is Prime | C++ Example
8:29
Portfolio Courses
Рет қаралды 21 М.
Check If A String Is A Palindrome | C Programming Example
10:56
Portfolio Courses
Рет қаралды 38 М.
you will never ask about pointers again after watching this video
8:03
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 143 МЛН