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

What does emoji p mean?

0 Answers  


write an interactive program to generate the divisors of a given integer.

7 Answers   TCS,


implement NAND gate logic in C code without using any bitwise operatior.

4 Answers   Alcatel,


What are the different pointer models in c?

4 Answers  


what are the stoge class in C and tel the scope and life time of it?

2 Answers   Tech Mahindra,


5) Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.without using big int and exponential function

1 Answers   TCS,


write an algorithm and a program to count the number of elements in a circularly singly linked list

1 Answers   Ignou,


Why main function is special give two reasons?

0 Answers  


What are different types of pointers?

0 Answers  


What is atoi and atof in c?

0 Answers  


c programming of binary addition of two binary numbers

4 Answers  


What does malloc () calloc () realloc () free () do?

0 Answers  


Categories