#include < stdio.h >
#include < conio.h >
void main()
{
int p,i,flag,j;
clrscr();
printf("To find Prime numbers within a given range\n\n");
while(1)
{
printf("Enter a number (1-1000) : ");
scanf("%d",&p);
if(p<1 p="">1000)
printf("\n\n\n***invalid input***\n\n\n");
else
break;
}
clrscr();
printf("\n\nprime numbers between 1-%d are listed below :\n\n",p);
for(i=1;i<=p;i++)
{
flag=1;
for(j=2;j<=i-1;j++)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
printf("%5d",i);
}
getch();
}
1>
#include < conio.h >
void main()
{
int p,i,flag,j;
clrscr();
printf("To find Prime numbers within a given range\n\n");
while(1)
{
printf("Enter a number (1-1000) : ");
scanf("%d",&p);
if(p<1 p="">1000)
printf("\n\n\n***invalid input***\n\n\n");
else
break;
}
clrscr();
printf("\n\nprime numbers between 1-%d are listed below :\n\n",p);
for(i=1;i<=p;i++)
{
flag=1;
for(j=2;j<=i-1;j++)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
printf("%5d",i);
}
getch();
}
1>
No comments:
Post a Comment