You are on page 1of 2

main()

{
int i,j=2,ch=0;
clrscr();
printf("\nENTER ANY NUMBER");
scanf("%d",&i);
while(j<=i/2)
{
if(i%j==0)
{
printf("%d IS NOT PRIME",i);
ch=1;
break;
}
else
{
j++;
}
}
if(ch==0)
{
printf("%d IS PRIME",i);
}
}
_____________________________________________________________
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf(" Enter the number upto which we have to find the prime number: ");
scanf("%d",&n);
printf("\n");
for(i=2;i<=n;i++)
{
for(j=2;j<=i-1;j++)
if(i%j==0)
break;
/*Number is divisble by some other number. So break out*/
if(i==j)
printf("\t%d",i);
/*Number was divisible by itself (that is, i was same as j)*/
}
/*Continue loop upto nth number*/
getch();
}
Read more: http://wiki.answers.com/Q/C_program_to_print_how_many_prime_numbers_a
re_there_from_1_to_50#ixzz1Rt1vuMc8
_____________________________________________________________
#include<stdio.
h>
#include<conio.h>
void main()
{
int count,i=1;
int a;
clrscr();
while(i<=500)
{

count=0;
a=1;
while(a<=i)
{
if(i%a==0)
count++;
a++;
}
if(count==2)
printf("%d\t",i);
i++;
}
getch();
}
_____________________________________________________________
#include <stdio.h>
void main()
{
int no,counter,counter1,check;
clrscr();
PRIME NO. SERIES
> );
printf( <
printf( \n\n\n\t\t\tINPUT THE VALUE OF N: );
scanf( %d ,&no);
printf( \n\nTHE PRIME NO. SERIES B/W 1 TO %d : \n\n ,no);
for(counter = 1; counter <= no; counter++)
{
check = 0;
//THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT.
for(counter1 = counter-1; counter1 > 1 ; counter1 )
if(counter%counter1 == 0)
{
check++;
// INCREMENT CHECK IF NO. IS NOT A PRIME NO.
break;
}
if(check == 0)
printf( %d\t ,counter);
}
getch();
}

You might also like