#include<stdio.h>
int main(void)
{
int a, b;
//takes the two input numbers
printf("Enter the two numbers\n");
scanf("%d %d", &a, &b);
//checks if the entered number is invalid
if((a < 0) || (b < 0))
{
printf("Invalid numbers");
return -1;
}
//for each number between a and b, checks either it is prime or not
for(int i = a; i <= b; i++)
{
int count = 0;
//counts the number of divisors of the number i with remainder 0
for(int j = 1; j <= i; j++)
{
if(i % j == 0)
{
count++;
}
}
//if number of divisors of the i is less than 3, which means the
//number is prime, it prints the number
if(count < 3)
{
printf("%d ", i);
}
}
return 0;
}
0
solved Make a program in C to show all existing prime numbers between two natural numbers [closed]