Pages

Ads 468x60px

Saturday, 2 June 2012

C PROGRAM FOR PRIME NUMBER


C PROGRAM FOR PRIME NUMBER



                         Prime number program in c: c program for prime number, this code
 prints prime numbers using c programming language. To check whether
 a number is prime or not see another code below. Prime number logic: 
a number is prime if it is divisible only by one and itself. Remember two
 is the only even and also the smallest prime number. First few prime
 numbers are 2, 3, 5, 7, 11, 13, 17....etc. Prime numbers have many applications
 in computer science and mathematics. A number greater than one can be 
factorized into prime numbers, For example 540 = 22*33*51





CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,j,a=0,i;
clrscr();
printf(" Please Enter a number :");
scanf("%d",&n);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Prime Number series is\n");
printf("**************************");
for(j=1;j<=n;j++)
{
for(i=2;i<j;i++)
{
if(j%i==0)
{
a=1;
goto x;
}
}
if((a==0)&&(j!=1))
{
printf("\n%d",j);
}
x:
a=0;
}
getch();
}

0 comments:

Post a Comment

Total Pageviews