0
23kviews
Write a program to display prime numbers between 1 to 1000.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 5 M

Year: Dec 2016

1 Answer
0
1.4kviews
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,n;
printf("Enter a range");
scanf("%d",&n);

if(n>=2)
{
printf("2\n");
}
for(num=1;num<=n;num++)
{
i=2;
while(i<=num-1)
{
    if(num%i==0)
    {
    break;
    }
    else if(i==num-1)
    {
    printf("%d\n",num);
    break;
    }
    i++  ;
}
}
    getch();
}
Output:
Enter a range: 1000
2
3
5
7
1
13
17
.
.
.
.
.
991
997
Please log in to add an answer.