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
How can I call a function with an argument list built up at run time?
What are preprocessor directives in c?
Write a progarm to find the length of string using switch case?
What is operator precedence?
What is meant by type specifiers?
Who is the founder of c language?
Why can't I perform arithmetic on a void* pointer?
explain what is fifo?
simple program of graphics and their output display
Which are low level languages?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
Is it possible to execute code even after the program exits the main() function?
writ a program to compare using strcmp VIVA and viva with its output.
What is c variable?
a program that can input number of records and can view it again the record