write the program for prime numbers?
Answer Posted / 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 |
Post New Answer View All Answers
What does p mean in physics?
How can you avoid including a header more than once?
What is meant by 'bit masking'?
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
Why is C language being considered a middle level language?
What is pointer & why it is used?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
why wipro wase
What are valid operations on pointers?
Where register variables are stored in c?
Can you mix old-style and new-style function syntax?
How can I find out how much free space is available on disk?
Can you please explain the scope of static variables?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE