Question about Operating Systems

1 Answer

Code for prime numbers in c

Prime numbers

Posted by on

1 Answer

  • Level 2:

    An expert who has achieved level 2 by getting 100 points

    MVP:

    An expert that gotĀ 5 achievements.

    Governor:

    An expert whose answer gotĀ voted for 20 times.

    Hot-Shot:

    An expert who has answered 20 questions.

  • Expert
  • 62 Answers

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

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

What is a prime number ?


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

2 Answers

How to reduce 61/82


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

Jun 29, 2014 | Operating Systems

1 Answer

Determining a prime number


wath is the link pro facebook hack v 1.5

Jan 10, 2014 | Operating Systems

1 Answer

Prime number


? 17 or 137 ?

Nov 15, 2012 | Operating Systems

1 Answer

Find the prime number between 1 to 50


using System;

class MainClass {
public static void Main() {
int num;
int i;
int factor;
bool isprime;


for(num = 1; num < 50; num++) {
isprime = true;
factor = 0;

// see if num is evenly divisible
for(i=2; i <= num/2; i++) {
if((num % i) == 0) {
// num is evenly divisible -- not prime
isprime = false;
factor = i;
}
}

if(isprime)
Console.WriteLine(num + " is prime.");
else
Console.WriteLine("Largest factor of " + num +
" is " + factor);
}

}
}

Feb 01, 2011 | Operating Systems

1 Answer

112493


> 112493

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

Dec 20, 2010 | Operating Systems

1 Answer

Generate prime nos upto n


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

1 Answer

I need a java source code file that is just like a ATM machine which saves the transactions...for example if you have withdrawn $1000 from your atm account and you have $5000 dollars...it would save the...


/* 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");

}

}

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

1 Answer

Need code


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)
  1. #include <stdio.h>
  2. int main(void) {
  3. int n,
  4. lcv,
  5. flag; /* flag initially is 1 and becomes 0 if we determine that n
  6. is not a prime */
  7. printf("Enter value of N > ");
  8. scanf("%d", &n);
  9. for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
  10. if ((n % lcv) == 0) {
  11. if (flag)
  12. printf("The non-trivial factors of %d are: \n", n);
  13. flag = 0;
  14. printf("\t%d\n", lcv);
  15. }
  16. }
  17. if (flag)
  18. printf("%d is prime\n", n);
  19. }
---------------------------------------------------------------------------------------------------------------------------------------------------

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

Not finding what you are looking for?
Operating Systems Logo

Related Topics:

95 people viewed this question

Ask a Question

Usually answered in minutes!

Top Operating Systems Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18299 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Prashant  Sharma
Prashant Sharma

Level 3 Expert

1127 Answers

Are you an Operating System Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...