#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
int M, N, i, j, flag, temp, count = 0;
clrscr();
printf(“Enter the value of M and N\n”);
scanf(“%d %d”, &M,&N);
if(N < 2)
{
printf(“There are no primes upto %d\n”, N);
exit(0);
}
printf(“Prime numbers are\n”);
temp = M;
if ( M % 2 == 0)
{
M++;
}
for (i=M; i<=N; i=i+2)
{
flag = 0;
for (j=2; j<=i/2; j++)
{
if( (i%j) == 0)
{
flag = 1;
break;
}
}
if(flag == 0)
{
printf(“%d\n”,i);
count++;
}
}
printf(“Number of primes between %d and %d = %d\n”,temp,N,count);
}
/*———————————
Output
Enter the value of M and N
15 45
Prime numbers are
17
19
23
29
31
37
41
43
Number of primes between 15 and 45 = 8
——————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to check whether a given number is prime or not and output the given number with suitable message
- C program to generate and print first N FIBONACCI numbers
- Sample – check if a number is prime
- C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
- C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
