Ad

Try the Following Five Programs

1) Program for Prime Number Generation

#include <stdio.h>

main()

{

int n,i=1,j,c;

clrscr();

printf("Enter Number Of Terms

");

printf("Prime Numbers Are Follwing

");

scanf("%d",&n);

while(i<=n)

{

c=0;

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

{

if(i%j==0)

c++;

}

if(c==2)

printf("%d ",i)

i++;

}

getch();

}

--------------------------------------------------------------------------------------------------------------------------------------------------

2)Program for finding the prime numbers

#include <stdio.h>

#include <conio.h>

void main()

{

int n,m,k,i,max;

char c;

clrscr();

repeat: max=0;

k=2;

n=1;

printf("You want prime numbers upto:- ");

scanf("%d",&max);

printf("

");

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

{

again: m=(n/k)*k;

if (m!=n)

k=k+1;

else

goto try1;

if (k < n/2)

goto again;

else

printf("%d",n);

printf(" ");

try1: n=n+1;

k=2;

}

fflush(stdin);

printf ("

Do you want to continue?(y/n):- ");

scanf("%c",&c);

if (c=='y')

goto repeat;

getch();

}

---------------------------------------------------------------------------------------------------------------------------------------------------

3)

- #include <stdio.h>
- int main(void) {
- int n,
- lcv,
- flag; /* flag initially is 1 and becomes 0 if we determine that n
- is not a prime */
- printf("Enter value of N > ");
- scanf("%d", &n);
- for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
- if ((n % lcv) == 0) {
- if (flag)
- printf("The non-trivial factors of %d are: \n", n);
- flag = 0;
- printf("\t%d\n", lcv);
- }
- }
- if (flag)
- printf("%d is prime\n", n);
- }

4)

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i,c=0;

clrscr();

printf("enter the number:");

scanf("%d",&n);

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

{

if(n%i==0)

{

c=c+1;

}

}

if(c==2)

printf("number is prime");

else

printf("number is not prime");

getch();

}

-------------------------------------------------------------------------

5)

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c;

clrscr();

printf("enter the number:");

scanf("%d",&a);

for(b=2;b<a/2;b++)

{

if(n%i==0)

{

printf("\n Its not a Prime number");

c=1;

break;

}

if(flag==0)

printf("\n Its a Prime Number");

getch();

}

}

Posted on Sep 12, 2008

Ad

Hi,

a 6ya Technician can help you resolve that issue over the phone in a minute or two.

Best thing about this new service is that you are never placed on hold and get to talk to real repair professionals here in the US.

click here to Talk to a Technician (only for users in the US for now) and get all the help you need.

Goodluck!

Posted on Jan 02, 2017

Ad

End Your Amazon Prime Membership

https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_ya_signin

https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_ya_signin

Mar 02, 2017 | Amazon Computers & Internet

No it isn't as 1,2,4,8 can be used to divide it prime's are only dividable by 1 or itself only

20 is 1,2,4,5,10

20 is 1,2,4,5,10

Jan 23, 2017 | The Computers & Internet

It used to be. **The idea is that a prime decomposition must be unique.** If you write 13=1*13, you can also write 13=1*1*1*....*1*13. If you allow 1 to be a prime number, there is no unicity of any prime factor decomposition. Any prime number would have a infinity number of prime decompositions.

Sep 28, 2014 | Computers & Internet

A prime number is a positive whole number (natural number) which cannot be divided into smaller whole numbers. In short, it can only be divided (integer division) by itself and 1.

First prime number is 2, then 3, 5, 7, 11, 13, 17, 19,

To generate a list of prime numbers the Greek Eratoshenes used a method called now the sieve Eratosthenes.

**all subsequent prime numbers**. If it is not divisible by any prime number, keep going but do not exceed the prime number that is closest yet smaller than square root of your number.

Enjoy.

First prime number is 2, then 3, 5, 7, 11, 13, 17, 19,

To generate a list of prime numbers the Greek Eratoshenes used a method called now the sieve Eratosthenes.

- Write all the natural numbers up to some chosen limit (100, 259, any limit )
- Remove 1 by crossing it ( 1 is no longer considered prime).
- The first prime number is 2.
**Circle the number 2.** - Go through the
**whole list**crossing out all the numbers that are multiple of 2, that is 4, 6, 8,10,12, ... - Repeat.
- The next prime number is 3 since it was not crossed out as a multiple of 2.
**Circle 3.** - Go through the
**whole list**crossing all the numbers that are multiples of 3, and which have not already been crossed out as multiples of 2 . - Number 4 has been crossed out already.
- Next prime number is 5.
**Circle 5** - Go through the
**whole list**crossing all the numbers that are multiple of 5 and which have not been crossed out already as multiples of 2, or 3 - Repeat:
- Next prime number is 7.
**Circle 7** **Go through the whole list again, crossing out the multiples of 7, and so on.**

Enjoy.

Nov 26, 2013 | Office Equipment & Supplies

"Prime Factorization" is finding **which prime numbers** multiply together to make the original number.

Example : What are the prime factors of 12 ?
It is best to start working from the smallest prime number, which is 2, so let's check:

12 ÷ 2 = 6

Yes, it divided evenly by 2. We have taken the first step!

But 6 is not a prime number, so we need to go further. Let's try 2 again:

6 ÷ 2 = 3

Yes, that worked also. And 3 **is** a prime number, so we have the answer:

**12 = 2 × 2 × 3**

As you can see, **every factor** is a **prime number**, so the answer must be right.

Note: **12 = 2 × 2 × 3** can also be written using exponents as **12 = 22 × 3**

Jun 22, 2011 | Computers & Internet

Just do a search for Sieve of Eratosthenes to find an efficient algorithm for finding prime numbers. You can probably find source code in multiple languages for this purpose as well.

Jul 06, 2009 | Microsoft Computers & Internet

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i,rem,prime,primchk=1,chk;

clrscr();

printf("\nEnter the limit\n");

scanf("%d",&n);

printf("\n\n\nThe prime numbers are\n");

printf("\n2\t3\t");

for(primchk=1;primchk<=n;primchk++)

{

for(i=2;i<primchk;i++)

{

if(primchk%i==0)

{

chk=1;

chk=0;

break;

}

if(i==primchk-1)

{

if(chk==0)

{

printf("%d\t",primchk);

chk=0;

}

}

}

}

getch();

}

#include<conio.h>

void main()

{

int n,i,rem,prime,primchk=1,chk;

clrscr();

printf("\nEnter the limit\n");

scanf("%d",&n);

printf("\n\n\nThe prime numbers are\n");

printf("\n2\t3\t");

for(primchk=1;primchk<=n;primchk++)

{

for(i=2;i<primchk;i++)

{

if(primchk%i==0)

{

chk=1;

chk=0;

break;

}

if(i==primchk-1)

{

if(chk==0)

{

printf("%d\t",primchk);

chk=0;

}

}

}

}

getch();

}

May 20, 2009 | Computers & Internet

Prime numbers can be calculated by using recursive algorithm

int i,j=1;

i++;

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

{

If (i%j==0)printf(" %d number is prime",&i );

else printf(" %d number is not prime",&i);

i++;

delay(20);

}

Ctrl break to terminate execution or other

int i,j=1;

i++;

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

{

If (i%j==0)printf(" %d number is prime",&i );

else printf(" %d number is not prime",&i);

i++;

delay(20);

}

Ctrl break to terminate execution or other

Jan 29, 2009 | Computers & Internet

write the following function and call it whenever you need to evaluate a number:

Private Function IsPrime(ByVal Number As Long) IsPrime = False Dim I As Long For I = LBound(Primes) To UBound(Primes) DoEvents Call UpdateStatus(Number, Primes(I)) If (Number Mod Primes(I) = 0) Then Exit Function If (Primes(I) >= Sqr(Number)) Then Exit For Next IsPrime = True End Function

Private Function IsPrime(ByVal Number As Long) IsPrime = False Dim I As Long For I = LBound(Primes) To UBound(Primes) DoEvents Call UpdateStatus(Number, Primes(I)) If (Number Mod Primes(I) = 0) Then Exit Function If (Primes(I) >= Sqr(Number)) Then Exit For Next IsPrime = True End Function

Jan 06, 2009 | Microsoft Visual Basic 6.0 for PC

Jan 19, 2018 | Computers & Internet

Jan 19, 2018 | Computers & Internet

Jan 19, 2018 | Logo Computers & Internet

212 people viewed this question

Usually answered in minutes!

×