C Program Prime Numbers between 2 given numbers
#include<stdio.h>
main()
{
int num1,num2,i,count=0,j;
printf("Enter a number 1\n");
scanf("%d",&num1);
printf("Enter a number 2\n");
scanf("%d",&num2);
printf("The Prime numbers between %d and %d are\n",num1,num2);
for(i=num1;i<=num2;i++)
{
count=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==2)
{
printf("%d\n",i);
}
}
}
Output:-
Enter a number 1
2000
Enter a number 2
2100
The Prime numbers between 2000 and 2100 are
2003
2011
2017
2027
2029
2039
2053
2063
2069
2081
2083
2087
2089
2099
Post a Comment
If you have any doubts, Please let me know
Thanks!