write the program for prime numbers?

Answers were Sorted based on User's Feedback



write the program for prime numbers?..

Answer / dharanya

Answer
# 10

Find all primes not larger than N.
I think it is the most efficient algorithm to find all
primes no larger than N.

int main(void)
{
int i,j, N;
int *pPrimes;
int nPrimes, is_prime;
printf("Input N:");
scanf("%d", &N);

pPrimes = new int [N/2];
nPrimes = 0;
for(i = 2; i<=N; i++)
{
is_prime = 1;
for(j=0;j<nPrimes; j++)
if (i%pPrimes[j] == 0)
{
is_prime = 0; break;
}
if (is_prime)
{
pPrimes[nPrimes++] = i;
}
}

printf("%d primes found less than %d:\n", nPrimes, N);
for (i=0; i< nPrimes; i++)
printf("%d ", pPrimes[i]);

Is This Answer Correct ?    0 Yes 2 No

write the program for prime numbers?..

Answer / natalija

I got one question! how can i make program in LSL (linden->second life script language) for prime numbers...not to cheek, but for readouot prime numbers?

Is This Answer Correct ?    7 Yes 10 No

write the program for prime numbers?..

Answer / neetu singh

#include<iostream.h>
#include<conio.h>
void main()
{
int n,i;
for(i=0;i<10;i++)
{
if(n<=o)
}
{
cout<<"number is prime");
cout<<"number is not prime");
getch();
}

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Interview Questions

how to find anagram without using string functions using only loops in c programming

1 Answers   Mind Tree, TCS,


how to write hello word without using semicolon at the end?

6 Answers   Accenture,


Explain how can I make sure that my program is the only one accessing a file?

0 Answers  


Why clrscr is used after variable declaration?

0 Answers  


What is conio h in c?

0 Answers  






What is clrscr ()?

0 Answers  


what do u mean by Direct access files? then can u explain about Direct Access Files?

0 Answers   LG Soft,


difference between native and cross compilers

0 Answers  


How many identifiers are there in c?

0 Answers  


which is faster execution: loops or recursion?

3 Answers  


What is the exact difference between '\0' and ""

3 Answers  


Not all reserved words are written in lowercase. TRUE or FALSE?

0 Answers  


Categories