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

If I have a char * variable pointing to the name of a function ..

0 Answers  


write aprogram for There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

1 Answers   iGate, Shashi, Source Bits, Subex,


How do I create a directory? How do I remove a directory (and its contents)?

0 Answers  


write a programming in c to find the sum of all elements in an array through function.

0 Answers  


Can a binary search tree be used as an index? If yes, how? Explain

0 Answers   TCS,






Why is sprintf unsafe?

0 Answers  


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

0 Answers  


Can we add pointers together?

0 Answers  


Write the following function in C. stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

4 Answers   OpenFeel,


What is meant by errors and debugging?

0 Answers  


What is the use of #include in c?

0 Answers  


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

0 Answers  


Categories