Here is source code of the C program to calculate the prime numbers in a given range. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to find prime numbers in a given range.
* Also print the number of prime numbers.
int num1, num2, i, j, flag, temp, count = 0;
printf("Enter the value of num1 and num2 \n");
scanf("%d %d", &num1, &num2);
if (num2 < 2)
printf("There are no primes upto %d\n", num2);
printf("Prime numbers are \n");
temp = num1;
if ( num1 % 2 == 0)
for (i = num1; i <= num2; i = i + 2)
flag = 0;
for (j = 2; j <= i / 2; j++)
if ((i % j) == 0)
flag = 1;
if (flag == 0)
printf("Number of primes between %d & %d = %d\n", temp, num2, count);
$ cc pgm17.c $ a.out Enter the value of num1 and num2 70 85 Prime numbers are 71 73 79 83 Number of primes between 70 and 85 = 4
Sanfoundry Global Education & Learning Series – 1000 C Programs.