/ * c program to print Prime Numbers Between 1 and N * /

#include<stdio.h>

void main()

{

int num,i=1,j,count;

//clrscr();

printf("Enter Num value To Print Prime Numbers between 1 and Num: ");

scanf("%d",&num);

printf("Prime Numbers upto %d :\n \n",num);

while(i<=num)

{

count=0;

for(j=1;j<=i;j++)

{

if(i%j==0) //checking whether num is dvisible by j

count++;

}

if(count==2) //if num is divisible by 2 numbers,then it is prime

printf("%d ",i);

i++;

}

printf("\n\n");

//getch();

}

Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

#include<stdio.h>

void main()

{

int num,i=1,j,count;

//clrscr();

printf("Enter Num value To Print Prime Numbers between 1 and Num: ");

scanf("%d",&num);

printf("Prime Numbers upto %d :\n \n",num);

while(i<=num)

{

count=0;

for(j=1;j<=i;j++)

{

if(i%j==0) //checking whether num is dvisible by j

count++;

}

if(count==2) //if num is divisible by 2 numbers,then it is prime

printf("%d ",i);

i++;

}

printf("\n\n");

//getch();

}

Output: ( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

ReplyDeleteBest way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |

Check out programming video tutorials on this YOUTUBE Channel

ReplyDeleteCheck out programming video tutorials on this YOUTUBE Channel

ReplyDeletethanks for help.

ReplyDeleteExcellent explanation by admin

ReplyDeletePrint Prime numbers from 1 to n

Easiest Program To How To Find Whether Given Number Is Prime Number Or Not

ReplyDeletewhat a lovely programme

ReplyDeletethanks a lot

so slow algo yet :(

ReplyDeletethis is a PYTHON program to calculate the prime factors of a number: ( quite fast and self made :p)

ReplyDeletenumber=int(input('enter the number to be factorized'));

print ('the entered number was %d'%number);

divisor=2;

import math

sr=math.sqrt(number);

i=0;

factors=dict({});

while number%2==0:

nwnumber=number/divisor;

factors[i]=divisor;

number=nwnumber;

i=i+1;

if number==0:

break;

divisor=3;

nwnumber=number;

while number!=1:

if nwnumber%divisor==0 :

factors[i]=divisor;

nwnumber=nwnumber/divisor;

i=i+1

continue;

elif nwnumber==1:

break;

elif math.sqrt(nwnumber)>divisor:

divisor=divisor+2

i=i+1

else:

i=i+1;

factors[i]=nwnumber;

break;

print ('the prime factors of the entered number are :');

print dict.values(factors)

cool man ;)

Deleteprint this

ReplyDelete23 21 24 19 26 15 28 11 30 7 36

I cam across this program. It seems interesting and easy to understand.

ReplyDeletehttp://www.codingalpha.com/prime-number-c-program/#include

int main()

{

int count=2,num;

printf("Enter a Number:\t");

scanf("%d",&num);

for(count=2;count<=num-1;count++)

{

if(num%count==0)

{

printf("%d is not a Prime Numer\n",num);

break;

}

}

if(count==num)

{

printf("%d is a Prime Number\n",num);

}

}Source: http://www.codingalpha.com/prime-number-c-program/

Prime number program in C

ReplyDeleteHelpful program, keep sharing

This point has dependably been one of my most loved subjects to peruse about. I have observed your post to be exceptionally energizing and brimming with great data. I will check your different articles in the blink of an eye.. Buzz Applications

ReplyDeleteA much faster algorithm would be to Check for only those numbers whose remainder is 1 or 5 when divided by 6 , but this algorithm excludes 2 and 3. So those could be taken care of

ReplyDeleteA much faster algorithm would be to Check for only those numbers whose remainder is 1 or 5 when divided by 6 , but this algorithm excludes 2 and 3. So those could be taken care of

ReplyDeleteA much faster algorithm would be to Check for only those numbers whose remainder is 1 or 5 when divided by 6 , but this algorithm excludes 2 and 3. So those could be taken care of

ReplyDeletemy program exits time limit...

ReplyDeletewhat I do...

i did not get you, can u plz explain clearly ?

Deletemy program exits time limit...

ReplyDeletewhat I do...

Prime Number Program in C

ReplyDelete#include

#include

void main()

{

int num,res=0;

clrscr();

printf("\nENTER A NUMBER: ");

scanf("%d",&num);

res=prime(num);

if(res==0)

printf("\n%d is a prime number",num);

else

printf("\n%d is not a prime number",num);

getch();

}

int prime(int n)

{

int i;

for(i=2;i<=n/2;i++)

{

if(n%i!=0)

continue;

else

return 1;

}

return 0;

}

Prime Number Distribution Series (PNDS), developed by the NSI team of mathematicians2 which computes the exact count of primes numbers.

ReplyDeleteWhat is a prime number? This definition explains what a prime number is and lists examples. See also different types of primes and links to information about prime number distribution .

ReplyDelete