Write a simple c program for prime number


















A prime number is a positive integer that is divisible only by 1 and itself. For example: 2, 3, 5, 7, 11, 13, If n is perfectly divisible by i , n is not a prime number.

In this case, flag is set to 1, and the loop is terminated using the break statement. So, if n is a prime number after the loop, flag will still be 0. However, if n is a non-prime number, flag will be 1. Visit this page to learn how you can print all the prime numbers between two intervals.

Course Index Explore Programiz. Popular Tutorials Data Types in C. C for Loop. Arrays in C Programming. Pointers in C. Then the entered number is copied into num. Here num is used to compare the result with the original. If the number is greater than 0, it will execute the statements following while. Here we have written a program to check prime number using a do-while loop.

The only difference in the above example that it first checks the condition i. This is a guide to Prime Numbers in C. Here we discuss what is prime number along with programs to check whether the number is prime or not using various loops. You may also have a look at the following articles to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy. Data Science.

Angular 7. Machine Learning. Data Structures. Operating System. Computer Network. Compiler Design. Computer Organization. Discrete Mathematics. Ethical Hacking. Computer Graphics. Software Engineering. Web Technology. Cyber Security.



0コメント

  • 1000 / 1000