Program to generate prime numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, n;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
printf("\nThe prime numbers are :\n\n");
for (i = 1; i <= n; i++)
{
if(i <= 3)
{
printf("%d\t", i);
}
else
{
for (j = 2; j <= i / 2; j++)
{
if (i % j == 0)
goto loop;
}
printf("%d\t", i);
loop : ;
}
}
getch();
}
Output:
Enter the limit : 10
The prime numbers are :
1 2 3 5 7
-
UpdatedDec 31, 2019
-
Views5,967
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order