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

Why can’t constant values be used to define an array’s initial size?

0 Answers  


What is the purpose of ftell?

0 Answers  


Why header files are used?

0 Answers  


How do shell structures work?

0 Answers  


what is meant by flushll() in c programming?

1 Answers  






Write a program to check whether a number is prime or not using c?

0 Answers  


What is the difference between procedural and declarative language?

0 Answers  


how to make program without <> in libray.

0 Answers  


What is a null pointer in c?

0 Answers  


What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); }

5 Answers   ADITI, Wipro,


. Write a program to get a string and to convert the 1st letter of it to uppercase

2 Answers   HTC,


Linked lists -- can you tell me how to check whether a linked list is circular?

0 Answers  


Categories