📚 Learn how to solve problems and build projects with these Free E-Books ⬇️ C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook 🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/ Experience the power of practical learning, gain career-ready skills, and start building real applications! This is a step-by-step course designed to take you from beginner to expert in no time! 💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10). Use it quickly, because it will be available for a limited time.
numofpn++; This is what I added to count how many prime numbers there are from 1 to 1000. I added it in the for loop on MAIN. Just sharing. Thanks for your videos.
You could optimise the code even further by only checking against previously found primes. For example. When you want to establish whether 11 is a prime you only need to test this by dividing by 2, 3 and 5 since those are prime numbers. Anything that will divide by 4 will also divide by 2 since 4 isn't a prime number (anything over 5 can't be it because that would result in a number smaller than 2 as Marko Shiva Pavlovic said before). I think this will be easiest by using a list (or a C++ equivalent) and iterating through the list. If you find a prime you add it to the list. For small numbers the time saved is minimal (for 11 you only skip the 4) but for larger primes the time saved can add up rather quickly. As a human this would be more difficult since you need to remember (or write down) the previous primes but computers are very good at this. Love your videos by the way. I did not know any C++ a couple of days ago and I have the hang of the basics now (I inherited a lot of C++ code that I either need to understand or rewrite from scratch in a language I know).
I know only tamil...and I searched a good youtube channel for learning c++ ..that time only i found your channel..and you is so good andyour communication is too understandable to learn easily and quickly..keep teach for us mam
Also we can write main function without any declaration of bool variable, the function isPrimeNumber can be written directly to if condition. void main() { for (int i = 1; i < 1000; i++) { if (isPrimeNumber(i)) cout
Big Thanks for sharing this video :) Good stuff for beginners like me . I (personally) took notice that my knowledge of bool functions weren't that deep. I adjusted (for my personal study and coding experience) the functions. I created a code which 1) shows all numbers that can be divided by 24 after telling it to the programme and 2) your "homework" which counts how many full days (in my case) there are. // --> 24h indication and full Day(s) converter hours; for (int i = 3; i
Very good video! I did a similar implementation for a prime checker in C a couple of months back and now that I am beginig to experiment with C++ im going to try this! Just a note to add: you dont need to check for a divisor by checking all the numbers less than the input number, you just need to check up to the ceil of the square root of the number.
declare and initialise count variable = 0 and use it in loop below is prime If statement that will count every prime number and will increase by one each time a primer number is detected . Thank you for such good tutorial
Nice video. Thank you! Very clear explanation. I used C++ in the 90s. Is such a joy watch this after so many years. You have a great content and I came to your channel through Brads.
I was born in 95. I'm glad to see that experienced people are visiting my channel as well! ☺️ Brad is unique. I've learned so many things on his channel, so it was a great honor to be presented as an educator on Traversy Media! 🥰
Really enjoyed functions and pointers playlist....and now i am confident about these topics....please consider making more videos more frequently about OOP concepts
I love this video and all of the modifications presented in the comments. One person presented a counter which indicates there are 9592 prime numbers between 1 and 100,000. It would be really helpful if those 9592 prime numbers could be exported to an external CSV file. Printing them on the screen is of limited utility.
2 years late (haha), but here's a modified version of her code that outputs data to a csv file named "Output", as well as puts it onto the screen for immediate viewing. All I really had to do was output it to a file instead of the console, which isn't hard (though I did end up doing both). I also added a simple prime counter, which does indeed count 9592 prime numbers (1 is excluded because it's technically not prime for reasons). #include #include using namespace std; bool isPrimeNumber(int number) { for (int i = 2; i < number; i++) { if (number % i == 0) return false; } return true; } void main() { int number; int noOfPrimes = 0; cout > number; ofstream outData("Output.csv"); for (int i = 2; i < number; i++) { bool isPrime = isPrimeNumber(i); if (isPrime) { noOfPrimes++; cout
hi Saldina, I am a seasoned programmer in other languages and always avoided C++....I dislike it ! I can't stand the squiggly brackets paradigm and the semi-colon requirements !! that said, the biggest issue for me has always been the teacher !! why....cause 1-clarity during explanations, 2- going off on tangents, 3-pace of explanations, and visuals of what your are explaining vs whats on screen !!! In all the "courses" I have tried to follow, I have to admit that you are the only one that has kept me listening and that's not easy to do! congrats !!! Enjoy the coffee and don't drink them all on the same day !! :) ...... one question - Why is there no semi-colon after i++ in your loop?
If you prototyped the functions I would reference your videos in my college classes. Consider using VS Code instead of Visual Studio since most students don't have access to it and the pause will confuse begginers. I know you have videos on the issue.
Thank you Saldina your explanation is so understandable but there is a little mistake in checking prime numbers, the program displays 1 as a prime number and 0 too and we can solve this problem by adding if statement
Hello !! One question: how can I keep track about the functions I or an other person did create ? - are there any "library" structures ? Thank you !!! for your excelent and outstanding work in your tutorials. It is a real pleisure to go through them - it makes programming a real fun time (-:
Appreciate your videos. I have a question. Can we save the function and main program as two separate files and run the main program. If yes can you make a video on this
you are such an amazing programmer glad i found you but can you help me with something? i am a student at the faculty of computer science and i want to study data science so can you make a video to explain what i am supposed to study to work in data science career
you just add a counter variable and set it equal to 0 then increment it by setting counter = counter++ but outside of the for loop . I had to try it a few times but it worked.
#include #include #include using namespace std; bool isPrimeNumber(int number){ for (int i = 2; i < number; i++) { if(number % i == 0) return false; } return true; } int main() { int counter = 0; for (int i = 1; i
*spoilers* I wanted to challenge myself by changing the program. I decided to change bool to int so that I could return the factor if it wasn't prime. Then after modifying to check all numbers 1-1000 I was bored with all the 2's. So I decided to have it go in reverse by starting with number/2 and counting backwards from there so that the final result showed the largest factor for each number if they weren't prime. I'm fairly proud of myself, took some playing around to figure out what I was doing wrong. I'm aware this is less efficient but I was just playing around. here is the code. I also added a count so it listed the total number of primes. #include using namespace std; int isPrime(int number) { for (int factor = number/2; factor > 1; factor--) { if (number % factor == 0) return (factor); } return 0; } int main() { int total = 0(); for (int number = 2; number < 1000; number++) { int isprime = isPrime(number); if (isprime == 0) cout
@codebeauty Watching your videos is fun. I especially like the way you build up your videos with the knowledge learned in the previous once and all the examples you use.
Thanks Saldina, I really like your videos. Maybe you can make a video on how to calculate all prime numbers from x to y with Threads ? It should be much faster to split the numbers and have multiple threads calculate the results ? But I also wonder how to give every thread the equal amout of work then ? Maybe you can make a video on this ? Thanks,
hey there im very happy with your videos thank you ....but i want to ask you about passing condition fir the loop saying int i = 1 so all the numbers between 1 to 1000 will be prime number This is not correct according to the definition of prime numbers, which should only be divisible by 1 and themselves.
Thanks for the video. Very clear and understandable. However since 1(one) is not considered a prime number, how can 1(one) be omitted from the output? Thanks.
what is default return type in function in c++ ?? As in c default type is int, so i guess it should be in c++ aswell since you told in one of your video that everything in c is correct in c++ also.
Dont mind but returning a single value from a function is super easy, its very easy even a 2 year old kid can do this .Can you tell me how to code a program in which when you pass an array of random numbers to a functions and return an array of prime numbers from that function and print that array with out printing garbage values.
If you declare a function above the main and u have the function below the main ()and pass parameters... do you also need to put those parameters in the declaration?
Great! 😊 You're progressing very fast! 😯 I'm currently preparing C++ crash course that covers a lot of concepts, so I'll definitely let you know when that is published. It is not meant for beginners, but I think that you will be able to understand and learn a lot of things.
just made a small change to the "for" loop to find out how many prime nr are between 1 and 1000: (added a count=0) int count = 0; //check all prime nr between 1 and 1000 for (int i = 1; i
Hello Saldina! Congratulations for all your work. I watched all your 19 videos from C++ for beginner and I found them very interesting. I was trying to solve the problem of number 1 by inserting at the end of the isPrimeNumber function, this condition: (number == 1)? return false : return true; ....but it does't works. Ididn't understand why. This one insted, works: if(number == 1) return false; else return true;
The ternary operator "?" can only return a value, it can't carry out commands. So C++ doesn't like the 'return' in the condition. You can achieve what you're trying to do by rearranging your condition like this: return (number == 1) ? false : true;
we can not do this in C or C++ directly but we can return the address of the array that has these values. Also this array should be dynamic array that is allocated by heap section of the memory
hallo Codebeauty, Great video. My quetion is how does it implement the prime number of 2? at line 5 in the for loop for(int i = 2; i < number; i++) if i take 2 as the number and i as my counter value , then (2
Yea. You are almost right. not the body of the function but the body of the for will not execute due to i < number condition. So it returns true to the main function. We did like that because we dont need chech whether 2 is a prime number or not. I hope you understand what i mean. If you have any question, I can explain more deeply
I don't know I'm struggling a bit but trying my best to understand. Also added how many prime nb their is........ #include using namespace std; bool isPrimeNumber(int number) { bool isPrime = true; for (int c = 2; c < number; c++) { if (number % c == 0) return false; } return true; } void main() { int counter = 0; for (int i = 1; i < 1000; i++) { bool isPrime = isPrimeNumber(i); if (isPrime) { cout
i did a program that interval is identified by user. Here it is: #include using namespace std; bool isprimenumber(int number = 1) { for (int i = 2; i < number; i++) { if (number % i == 0) return false; } return((number == 0) || (number == 1)) ? false : true; } void main() { int start, last; int counter = 0; cout > start; cout > last; for (int j = (start-1); j
Hey Saldina I''m from Pakistan and i am studying computer science now i am in 3rd semester we are studying c++ and object oriented programing your videos give me much more help. i ust write a code for which the user input a number this will show all prime and non prime numbers btw the user enter and also show how many prime numbers and non prime numbers. #include using namespace std; //find all prime numbers and non prime numbers between which the user is entered //this is the algrithm for finding prime number and non prime numbers bool isPrimeNumber(int number) { bool isPrimeFlag = true; for(int i = 2 ; i < number ; i++) { if(number % i == 0) { isPrimeFlag = false; break; } } return isPrimeFlag; } int main() { int number; int primeNumbers = 0; int nonPrimeNumbers = 0; cout > number; for (int i = 0; i
like that :) #include using namespace std; bool isprimenumber(int number) { bool isprime = true; for (int i = 2;i < number;i++) { if (number % i == 0) return false; } return true;
You are such a great teacher i understand much better here than my class room but i have a request can you please tie your hairs cuz it always grab attention towards you
a program that counts the number of prime numbers b/w a given input #include using namespace std; bool isPrimeNumber(int number); int main() {
int number1; int number2; cout > number1; cout > number2; int count=0; for (int i = number1; i < number2; i++) { bool isprimeflag=isPrimeNumber(i); if (isprimeflag) { cout
#include using namespace std; bool Is_Prime_Number(int); // declaration/prototype int main() { int input_number,sum_ofPrime=0; cout > input_number; for (int the_prime=1; the_prime
namespace ConsoleApp9 { internal class Program { static void Main(string[] args) { double a, b; Console.Write("enter number A: "); a = Convert.ToDouble(Console.ReadLine()); Console.Write("enter number B: "); b = Convert.ToDouble(Console.ReadLine()); double result = Sum(a, b); Console.WriteLine(result); Console.ReadLine(); } static double Sum(double a, double b) { return a + b; } } }
Saldina I built your own code, it doesn't work as well, it gives errors, I will post the code here and waiting for comments #include using namespace std; bool isPrime(int Number) { for (int i = 2; i < Number; i++) { if (Number % i == 0) { return false; } else { return true; } } } int main() { int number; cin >> number; for (int i = 1; i
I tried this way....... #include using namespace std; bool isPrimeNumber(int number) { for (int i = 2; i < number; i++) { if (number % i == 0) { return false; } } return true; } void main() { int range; int counter = 0; cout > range; for (int i = 1; i
Hi, my version with user input of numbers he wants to check and a counter of how many prime numbers in the specified range: #include bool isPrimeNumber(int number); int num; int main() { std::cout > num; int count = 0; for (size_t i = 1; i
@@ronjackson8829 Thanks for the reply. Sorry for my bad english (i'm a 49 year old german). I have started out with learning to code this year with some HTML, CSS and Javascript and wanted to improve my skills with some C++, because i think it helps to learn any other language. And it does. Learning Javascript feels so much easier for me now, with some knowledge of C++ and from all the TH-cam Courses i have tried this year, this is the first where i understood everything.
Nice... Just one thing to add ..using square root of n instead n/2 will improve the performance of the program especially when u are dealing with numbers as large as 100,000
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.
You are really a great teacher. I wish if you used simple code here though, to teach us about function return.
numofpn++;
This is what I added to count how many prime numbers there are from 1 to 1000. I added it in the for loop on MAIN. Just sharing. Thanks for your videos.
Your explanations are so, so clear and understandable. Glad I found you!
I'm happy that you found me 😉🤗
Way better than my teachers. You doing a great job.
🤗🥰🥰
You could optimise the code even further by only checking against previously found primes.
For example. When you want to establish whether 11 is a prime you only need to test this by dividing by 2, 3 and 5 since those are prime numbers. Anything that will divide by 4 will also divide by 2 since 4 isn't a prime number (anything over 5 can't be it because that would result in a number smaller than 2 as Marko Shiva Pavlovic said before). I think this will be easiest by using a list (or a C++ equivalent) and iterating through the list. If you find a prime you add it to the list.
For small numbers the time saved is minimal (for 11 you only skip the 4) but for larger primes the time saved can add up rather quickly. As a human this would be more difficult since you need to remember (or write down) the previous primes but computers are very good at this.
Love your videos by the way. I did not know any C++ a couple of days ago and I have the hang of the basics now (I inherited a lot of C++ code that I either need to understand or rewrite from scratch in a language I know).
I know only tamil...and I searched a good youtube channel for learning c++ ..that time only i found your channel..and you is so good andyour communication is too understandable to learn easily and quickly..keep teach for us mam
Also we can write main function without any declaration of bool variable, the function isPrimeNumber can be written directly to if condition.
void main()
{
for (int i = 1; i < 1000; i++) {
if (isPrimeNumber(i))
cout
Big Thanks for sharing this video :) Good stuff for beginners like me . I (personally) took notice that my knowledge of bool functions weren't that deep.
I adjusted (for my personal study and coding experience) the functions. I created a code which 1) shows all numbers that can be divided by 24 after telling it to the programme and 2) your "homework" which counts how many full days (in my case) there are.
// --> 24h indication and full Day(s) converter hours;
for (int i = 3; i
YOU ARE A GREAT TEACHER
I'm A Big fan to your voice and the way you teach us.
Love Form Bangladesh
Very good video! I did a similar implementation for a prime checker in C a couple of months back and now that I am beginig to experiment with C++ im going to try this!
Just a note to add: you dont need to check for a divisor by checking all the numbers less than the input number, you just need to check up to the ceil of the square root of the number.
Pozdrav od Makedonija
You are explain very , very good ...
i consider myself very happy because i have found such an amazing teacher😍
You are the best teacher I've seen so far. And best is an understatment. Thank you for all you do for the community Saldina
You're such a great teacher, Saldina!
declare and initialise count variable = 0 and use it in loop below is prime If statement
that will count every prime number and will increase by one each time a primer number is detected .
Thank you for such good tutorial
Excellent 👍. All your tutoring so far has been really EXCELLENT 👍 for me, many thanks and please continue ☺️
❤️🥰
Hi, I'm from Russia. I'm watching you on January 1 at 20:24. All the best to you.
Nice video. Thank you!
Very clear explanation.
I used C++ in the 90s.
Is such a joy watch this after so many years.
You have a great content and I came to your channel through Brads.
I was born in 95. I'm glad to see that experienced people are visiting my channel as well! ☺️
Brad is unique. I've learned so many things on his channel, so it was a great honor to be presented as an educator on Traversy Media! 🥰
it was so fantastic your explanation is so best than others keep it up
🤗🥰🥰
Really enjoyed functions and pointers playlist....and now i am confident about these topics....please consider making more videos more frequently about OOP concepts
I love this video and all of the modifications presented in the comments. One person presented a counter which indicates there are 9592 prime numbers between 1 and 100,000. It would be really helpful if those 9592 prime numbers could be exported to an external CSV file. Printing them on the screen is of limited utility.
2 years late (haha), but here's a modified version of her code that outputs data to a csv file named "Output", as well as puts it onto the screen for immediate viewing. All I really had to do was output it to a file instead of the console, which isn't hard (though I did end up doing both). I also added a simple prime counter, which does indeed count 9592 prime numbers (1 is excluded because it's technically not prime for reasons).
#include
#include
using namespace std;
bool isPrimeNumber(int number) {
for (int i = 2; i < number; i++) {
if (number % i == 0)
return false;
}
return true;
}
void main()
{
int number;
int noOfPrimes = 0;
cout > number;
ofstream outData("Output.csv");
for (int i = 2; i < number; i++) {
bool isPrime = isPrimeNumber(i);
if (isPrime) {
noOfPrimes++;
cout
Interesante. Me gustan tus videos, aunque la traducción automática no es tan buena, pero te voy entendiendo. Gracias por tu dedicación.
Great video
int main()
{
int c = 0;
6 for(int i = 1; i
Thanks my sister I am more enjoy your Explanation and I am more understand c++ function
#include
using namespace std;
bool isprimenumber(int value){
bool isprim=true;
for (int i=2;i
Thank you so much, I completely missed the idea of using counters for this process.
hi Saldina, I am a seasoned programmer in other languages and always avoided C++....I dislike it ! I can't stand the squiggly brackets paradigm and the semi-colon requirements !! that said, the biggest issue for me has always been the teacher !! why....cause 1-clarity during explanations, 2- going off on tangents, 3-pace of explanations, and visuals of what your are explaining vs whats on screen !!! In all the "courses" I have tried to follow, I have to admit that you are the only one that has kept me listening and that's not easy to do! congrats !!! Enjoy the coffee and don't drink them all on the same day !! :) ...... one question - Why is there no semi-colon after i++ in your loop?
If you prototyped the functions I would reference your videos in my college classes. Consider using VS Code instead of Visual Studio since most students don't have access to it and the pause will confuse begginers. I know you have videos on the issue.
Thank you Saldina your explanation is so understandable but there is a little mistake in checking prime numbers, the program displays 1 as a prime number and 0 too and we can solve this problem by adding if statement
Hello !! One question: how can I keep track about the functions I or an other person did create ? - are there any "library" structures ?
Thank you !!! for your excelent and outstanding work in your tutorials. It is a real pleisure to go through them - it makes programming a real fun time (-:
your explination i s just so perrrfeecttt
Appreciate your videos. I have a question. Can we save the function and main program as two separate files and run the main program. If yes can you make a video on this
Thanks for such a great explanation.
You are Awesome Mam,I love to watch your videos...These are very helpful...
you are such an amazing programmer glad i found you but can you help me with something?
i am a student at the faculty of computer science and i want to study data science so can you make a video to explain what i am supposed to study to work in data science career
Very great explanation ..thank for the video
Thanks a billion.
I just need to know the difference between definition and declaration in coding
Great video, you made the concept clear to understand, but 1 is not prime
good job keep up doing the good teaching Iam very greatful to you thanks alot
the number of prime numbers between
1 and 100 is : 25
1 and 1000 is : 168
1 and 10000 is : 1229
1 and 100000 is : 9592
you just add a counter variable and set it equal to 0 then increment it by setting counter = counter++ but outside of the for loop . I had to try it a few times but it worked.
you help me a lot, thank you!!!
#include
#include
#include
using namespace std;
bool isPrimeNumber(int number){
for (int i = 2; i < number; i++)
{
if(number % i == 0)
return false;
}
return true;
}
int main()
{
int counter = 0;
for (int i = 1; i
15:06 Refactoring means improving the internal structure and readability of a function without changing its external behavior or functionality
*spoilers* I wanted to challenge myself by changing the program. I decided to change bool to int so that I could return the factor if it wasn't prime. Then after modifying to check all numbers 1-1000 I was bored with all the 2's. So I decided to have it go in reverse by starting with number/2 and counting backwards from there so that the final result showed the largest factor for each number if they weren't prime. I'm fairly proud of myself, took some playing around to figure out what I was doing wrong. I'm aware this is less efficient but I was just playing around. here is the code.
I also added a count so it listed the total number of primes.
#include
using namespace std;
int isPrime(int number) {
for (int factor = number/2; factor > 1; factor--) {
if (number % factor == 0)
return (factor);
}
return 0;
}
int main() {
int total = 0();
for (int number = 2; number < 1000; number++) {
int isprime = isPrime(number);
if (isprime == 0)
cout
Try to use (number/2) instead of number in for loop.
Can you paste the code? 🤔
@@CodeBeauty for(int i =2;i
Well, that is a nice optimization! 😍
Same result with half the iterations! 🤓
@@CodeBeauty mathematics 😁
If you use (number/2) the program will return 4 as prime number which is not right...
Thank you m'am.
Great job
As usually looking gorgeous ❤️
And video was usefull and simple
@codebeauty Watching your videos is fun. I especially like the way you build up your videos with the knowledge learned in the previous once and all the examples you use.
Thanks Saldina,
I really like your videos.
Maybe you can make a video on how to calculate all prime numbers from x to y with Threads ?
It should be much faster to split the numbers and have multiple threads calculate the results ? But I also wonder how to give every thread the equal amout of work then ?
Maybe you can make a video on this ?
Thanks,
hey there im very happy with your videos thank you ....but i want to ask you about passing condition fir the loop saying int i = 1 so all the numbers between 1 to 1000 will be prime number This is not correct according to the definition of prime numbers, which should only be divisible by 1 and themselves.
a beauty from a beauty
Thanks for the video. Very clear and understandable. However since 1(one) is not considered a prime number, how can 1(one) be omitted from the output? Thanks.
Hi, you either set the initial value of i to 2 or extend the condition for evaluation of i as follows:
if (i!=1 && isPrime) {
cout
i love you teacher
what is default return type in function in c++ ?? As in c default type is int, so i guess it should be in c++ aswell since you told in one of your video that everything in c is correct in c++ also.
can we use other thing rather than bool
Nice explanation
Perfect but 1 is not a prime number. 22:04
Dont mind but returning a single value from a function is super easy, its very easy even a 2 year old kid can do this .Can you tell me how to code a program in which when you pass an array of random numbers to a functions and return an array of prime numbers from that function and print that array with out printing garbage values.
If you declare a function above the main and u have the function below the main ()and pass parameters... do you also need to put those parameters in the declaration?
Nevermind, you answered my question in the next video😅
Here is my upgraded code:
int main()
{
int k = 0;
for( int i=2; i
Great! 😊 You're progressing very fast! 😯
I'm currently preparing C++ crash course that covers a lot of concepts, so I'll definitely let you know when that is published. It is not meant for beginners, but I think that you will be able to understand and learn a lot of things.
just made a small change to the "for" loop to find out how many prime nr are between 1 and 1000: (added a count=0)
int count = 0;
//check all prime nr between 1 and 1000
for (int i = 1; i
int main() {
int Hits=0;
for (int i=1; i
So you also no need to create a new variable in line 15 : bool isPrime. You can use without it like 'if (isPrimeNumber(i)) cout
You don't have to check "every number
I just love you!
Hello Saldina! Congratulations for all your work. I watched all your 19 videos from C++ for beginner and I found them very interesting.
I was trying to solve the problem of number 1 by inserting at the end of the isPrimeNumber function, this condition:
(number == 1)? return false : return true; ....but it does't works. Ididn't understand why.
This one insted, works: if(number == 1) return false;
else return true;
The ternary operator "?" can only return a value, it can't carry out commands. So C++ doesn't like the 'return' in the condition.
You can achieve what you're trying to do by rearranging your condition like this: return (number == 1) ? false : true;
@@QuietlyWrong thank you
Thanks
This one is quite tough
What do you use if you need multiple return values?
we can not do this in C or C++ directly but we can return the address of the array that has these values. Also this array should be dynamic array that is allocated by heap section of the memory
why we are not using {} sign for code below ?
if(isPrimeFlag)
cout
Number of prime numbers between 1 and 100000
int count = 0;
for (int i = 1; i
No others explanation will match with urs
hallo Codebeauty,
Great video. My quetion is how does it implement the prime number of 2? at line 5 in the for loop for(int i = 2; i < number; i++)
if i take 2 as the number and i as my counter value , then (2
Yea. You are almost right. not the body of the function but the body of the for will not execute due to i < number condition. So it returns true to the main function. We did like that because we dont need chech whether 2 is a prime number or not. I hope you understand what i mean. If you have any question, I can explain more deeply
I don't know I'm struggling a bit but trying my best to understand. Also added how many prime nb their is........
#include
using namespace std;
bool isPrimeNumber(int number) {
bool isPrime = true;
for (int c = 2; c < number; c++)
{
if (number % c == 0)
return false;
}
return true;
}
void main()
{
int counter = 0;
for (int i = 1; i < 1000; i++)
{
bool isPrime = isPrimeNumber(i);
if (isPrime)
{
cout
Total prime number count between 1 and the number user will enter:
#include
using namespace std;
bool isPrime(int n);
int main()
{
int num, count=0;
coutnum;
for(int j=1; j
is it still safe to do it this way?
if(isPrimeNumber(number)){
cout
Yes, indeed. That Boolean isPrime was unnecessary.
i love u teacher
There's a small bug, which is a prime number must be greater than 1.
the best
am just finished 'c++ for beginners' now am here but am think this one is harder.
int num;
cin >> num;
if (prime(num) == true ) {
cout
i did a program that interval is identified by user. Here it is:
#include
using namespace std;
bool isprimenumber(int number = 1)
{
for (int i = 2; i < number; i++)
{
if (number % i == 0)
return false;
}
return((number == 0) || (number == 1)) ? false : true;
}
void main() {
int start, last;
int counter = 0;
cout > start;
cout > last;
for (int j = (start-1); j
Hey Saldina
I''m from Pakistan and i am studying computer science now i am in 3rd semester we are studying c++ and object oriented programing your videos give me much more help.
i ust write a code for which the user input a number this will show all prime and non prime numbers btw the user enter and also show how many prime numbers and non prime numbers.
#include
using namespace std;
//find all prime numbers and non prime numbers between which the user is entered
//this is the algrithm for finding prime number and non prime numbers
bool isPrimeNumber(int number)
{
bool isPrimeFlag = true;
for(int i = 2 ; i < number ; i++)
{
if(number % i == 0)
{
isPrimeFlag = false;
break;
}
}
return isPrimeFlag;
}
int main()
{
int number;
int primeNumbers = 0;
int nonPrimeNumbers = 0;
cout > number;
for (int i = 0; i
bool isPrimeFlag = (number >= 2);
int max = (int) sqrt(number); // I used sqrt() function instead of counter*counter
like that :)
#include
using namespace std;
bool isprimenumber(int number)
{
bool isprime = true;
for (int i = 2;i < number;i++)
{
if (number % i == 0)
return false;
}
return true;
}
int main() {
int counter = 0;
for (int i = 2;i
You are such a great teacher i understand much better here than my class room but i have a request can you please tie your hairs cuz it always grab attention towards you
Sound please
Thank u for this video, its amazing..
Here the count, how many prime number in between 1 to n number
#include
using namespace std;
{
for(int i=2; i>n;
int count=0;
for(int i=1; i
a program that counts the number of prime numbers b/w a given input
#include
using namespace std;
bool isPrimeNumber(int number);
int main() {
int number1;
int number2;
cout > number1;
cout > number2;
int count=0;
for (int i = number1; i < number2; i++) {
bool isprimeflag=isPrimeNumber(i);
if (isprimeflag) {
cout
Why are you called codebeauty? What does code have to do with beauty?
Coz I'm beauty and I do code 😏😁
@@CodeBeauty can’t argue with that.
@@CodeBeauty You're absolutely right :D
16:41 return 0
#include
using namespace std;
bool Is_Prime_Number(int); // declaration/prototype
int main() {
int input_number,sum_ofPrime=0;
cout > input_number;
for (int the_prime=1; the_prime
where is the code!!
#include
using namespace std;
bool PrimeNumber(int number);
int main()
{
int count=0;
for(int i=2; i
namespace ConsoleApp9
{
internal class Program
{
static void Main(string[] args)
{
double a, b;
Console.Write("enter number A: ");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("enter number B: ");
b = Convert.ToDouble(Console.ReadLine());
double result = Sum(a, b);
Console.WriteLine(result);
Console.ReadLine();
}
static double Sum(double a, double b)
{
return a + b;
}
}
}
the sound in short videos where you dancing is very high and where peoples learning something useful is very slow what type of data is this
18:00
Why your audio so weak?
Saldina I built your own code, it doesn't work as well, it gives errors, I will post the code here and waiting for comments
#include
using namespace std;
bool isPrime(int Number)
{
for (int i = 2; i < Number; i++)
{
if (Number % i == 0)
{
return false;
}
else
{
return true;
}
}
}
int main()
{
int number;
cin >> number;
for (int i = 1; i
I tried this way.......
#include
using namespace std;
bool isPrimeNumber(int number) {
for (int i = 2; i < number; i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
void main() {
int range;
int counter = 0;
cout > range;
for (int i = 1; i
Hi, my version with user input of numbers he wants to check and a counter of how many prime numbers in the specified range:
#include
bool isPrimeNumber(int number);
int num;
int main() {
std::cout > num;
int count = 0;
for (size_t i = 1; i
Thanks for the example. I was having trouble understanding how to implement the count into the code.
@@ronjackson8829 Thanks for the reply. Sorry for my bad english (i'm a 49 year old german). I have started out with learning to code this year with some HTML, CSS and Javascript and wanted to improve my skills with some C++, because i think it helps to learn any other language. And it does. Learning Javascript feels so much easier for me now, with some knowledge of C++ and from all the TH-cam Courses i have tried this year, this is the first where i understood everything.
Bernd Baberske NP...I really like the instructor’s style here.
Nice... Just one thing to add ..using square root of n instead n/2 will improve the performance of the program especially when u are dealing with numbers as large as 100,000