C Program to Print Prime Numbers

« Previous Program Next Program »

Print Prime Numbers in C

To print all prime number between the particular range in C programming, you have to ask to the user to enter the range (i.e., ask to enter the starting and ending number ), and check division from 2 to one less that that number, if the number is divided by any number from 2 to on less than (n-1) that number then that number will not be prime otherwise that will be prime number

C Programming Code to Print Prime Numbers

To print prime number between range for example : to print prime number between 3 to 29, here 3 is the starting number and 29 is the ending number, so following C program ask to the user to enter the starting and ending number to find and print all the prime numbers exists between the given range (here we are including the starting and ending number also if they are prime):

/* C Program - Print Prime Numbers */
void main()
	int start, end, i, j, count=0;
	// to print all prime number between any range
	// enter the two number (starting and ending)
	printf("Enter starting number : ");
	printf("Enter ending number : ");
	printf("Prime Number Between %d and %d is :\n", start, end);
	for(i=start; i<=end; i++)
		for(j=2; j<i; j++)
			printf("%d  ",i);

When the above C Program is compile and executed, it will produce the following result:

c program print prime numbers

Same Program in Other Programming Language

You may also like same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test