C program to print all prime numbers between 1 to n – All those who are searching for Prime Number Program in C can check it out all the details here. This code prints prime numbers using c programming language. Any whole number which is greater than 1 and has only two factors that is 1 and the number itself, is called a prime number. Here is source code of the C program to check if a given number is prime. The C program is successfully compiled and run on a Linux system. Let’s see the prime number program in C. In this c program, we will take an input from the user and check whether the number is prime or not.
Input lower limit: 1
Input upper limit: 10
Output prime numbers between 1-10: 2, 3, 5, 7
Program to print prime numbers between 1 to n
* C program to print all prime numbers between 1 to n
i, j, n, isPrime;
//isPrime is used as flag variable
/* Reads upper limit to print prime */
"Find prime numbers between 1 to : "
"\nAll prime numbers between 1 to %d are:\n"
/* Finds all Prime numbers between 1 to n */
(i=2; i<=n; i++)
/* Assume that the current number is Prime */
isPrime = 1;
/* Check if the current number i is prime or not */
(j=2; j<=i/2; j++)
* If i is divisible by any number other than 1 and self
* then it is not prime number
isPrime = 0;
/* If the number is prime then print */
"%d is Prime number\n"
So, above code is totally free of error you can easily use this for C program to print all prime numbers between 1 to n, Prime Number Program in C. Above we have shared each and everything about Prime Number Program in C. If you have any query or problem connect with us. Comment on below box for any query.