Prime numbers

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

Posted on Jan 29, 2009

A prime number is a whole number greater than one which has no divisors except one and itself. A composite number is a whole number greater than one that isn't prime, that is, a product of two or more whole numbers. See http://en.wikipedia.org/wiki/Prime_number

Jul 07, 2014 | Operating Systems

61 is a prime number, thus 61/82 is already reduced to simplest terms.

Jun 29, 2014 | Operating Systems

wath is the link pro facebook hack v 1.5

Jan 10, 2014 | Operating Systems

bool isprime;

isprime =

factor = 0;

// see if num is evenly divisible

// num is evenly divisible -- not prime

isprime =

factor = i;

}

}

Console.WriteLine(num + " is prime.");

Console.WriteLine("Largest factor of " + num +

" is " + factor);

}

}

}

Feb 01, 2011 | Operating Systems

> 112493

This is NOT a "prime" number, because: 4891 * 23 = 1679 * 67 = 1541 * 73 = 112493

This is NOT a "prime" number, because: 4891 * 23 = 1679 * 67 = 1541 * 73 = 112493

Dec 20, 2010 | Operating Systems

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 Operating Systems

/* Program to Find whether number is Prime or Not. */

class PrimeNo{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int flag=0;

for(int i=2;i<num;i++){

if(num%i==0)

{

System.out.println(num+" is not a Prime Number");

flag = 1;

break;

}

}

if(flag==0)

System.out.println(num+" is a Prime Number");

}

}

class PrimeNo{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

int flag=0;

for(int i=2;i<num;i++){

if(num%i==0)

{

System.out.println(num+" is not a Prime Number");

flag = 1;

break;

}

}

if(flag==0)

System.out.println(num+" is a Prime Number");

}

}

May 16, 2009 | Microsoft Windows XP Professional With...

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)

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();

}

}

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();

}

}

Sep 02, 2008 | Operating Systems

95 people viewed this question

Usually answered in minutes!

×