Tuesday, 28 August 2012

c program for prime number between 1 to n

For beginners
{I am going write the c program but before you need a c compiler(software).there are a lot of compilers(software) for windows 7  like Code::Blocks,dev c++ Download dev c++ its free and install it in your computer.open  dev c++ go to file-->new-->source file.}  


#include <stdio.h>
#include <conio.h>
int main (void)
{
int p, d,n;
_Bool isPrime;
printf("enter a number(you will get all prime numbers upto that number)\n");
scanf("%d",&n);
for ( p = 2; p <= n; ++p ) 
{
isPrime = 1;
for ( d = 2; d < p; ++d )
if ( p % d == 0 )
isPrime = 0;
if ( isPrime != 0 )
printf ("%i ", p);
}
printf ("\n");
getch();
return 0;
}

For beginners
{After typing this program go to execute-->compile & run-->a window will pop-up-->give file name:(anything u like)-->save as type: c source files-->click save.}

IS IT HELPFIL? comment.

No comments:

Post a Comment