write the program for prime numbers?

Answer Posted / karthikeyan murugesan

hi u can try this one for prime number and generation ::
#include<stdio.h>
void main()
{
int n,i=1,j,c;
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
{
printf("%d",i);
i++;
}
}
getch();
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what does the function toupper() do?

633


How is null defined in c?

652


How can I remove the leading spaces from a string?

632


What is the purpose of macro in C language?

659


In a switch statement, explain what will happen if a break statement is omitted?

637






What are the advantages of Macro over function?

1198


Tell us bitwise shift operators?

596


What are pointers? Why are they used?

627


What is formal argument?

648


Is there anything like an ifdef for typedefs?

700


What is character constants?

714


What are register variables in c?

575


What is malloc calloc and realloc in c?

666


Give differences between - new and malloc() , delete and free() ?

610


Explain what is meant by 'bit masking'?

642