Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, j, count;
clrscr();
printf("Enter any Number : ");
scanf("%d", &n);
printf("Prime numbers from 1 to %d is : \n", n);
for(i=1; i<=n; i++)
{
count=0;
for(j=1; j<=i; j++)
{
if(i%j==0)
count++;
}
if(count==2)
printf("%d\t", 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
Next Topic :
Previous Topic :
No comments:
Post a Comment