Monday, 16 March 2015

Program to generate prime numbers Using C

# 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() ;
}

RUN 1 :
~~~~~~~
Enter the limit : 10
The prime numbers are :
1 2 3 5 7

No comments:

Post a Comment