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

Write a program with dynamically allocation of variable.

607


Is it better to use malloc() or calloc()?

654


What are the advantages and disadvantages of pointers?

584


Explain About fork()?

653


When is the “void” keyword used in a function?

847






What is the difference between printf and scanf )?

601


Where are some collections of useful code fragments and examples?

721


Is Exception handling possible in c language?

1588


Are there namespaces in c?

571


How can I prevent another program from modifying part of a file that I am modifying?

618


What is int main () in c?

630


What is #define?

578


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2457


What is anagram in c?

521


Explain what is the difference between #include and #include 'file' ?

591