Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n1, n2, i, j, count;
clrscr();
printf("Enter Starting Number : ");
scanf("%d", &n1);
printf("Enter Ending Number :");
scanf("%d", &n2);
for(i=n1; i<=n2; i++)
{
count=0;
for(j=1; j<=i; j++)
{
if(i%j==0)
count++;
}
if(count==2)
printf("\t%d", i);
}
getch();
}
Output:
Enter any Number : 100
Prime numbers from 1 to 100 is :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Enter Starting Number : 1
Enter Ending Number : 100
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Enter Starting Number : 1
Enter Ending Number : 10
2 3 5 7
Enter Starting Number : 1
Enter Ending Number : 50
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
No comments:
Post a Comment