write the program for prime numbers?

Answer Posted / kiran kumar maharana

#include<iostream.h>
#include<conio.h>
int prime(int);
void main()
{
int n;
cout<<"enter a no.";
cin>>n;
int x;
x=prime(n);
if(x==1)
cout<<"prime";

else
cout<<"not a prime no.";

}
int prime(int n)
{
int i,count=0;
if(n<2)
{
return 0;
}
else
{for(i=2;i<n;i++)

{
if(n%i==0)
{
count++;
}
}
if(count>=1)
{

return 0;

}
else
return 1;}

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are nested functions in c?

568


ATM machine and railway reservation class/object diagram

4807


What is null character in c?

695


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

1895


Should a function contain a return statement if it does not return a value?

601






Explain 'far' and 'near' pointers in c.

710


What is else if ladder?

614


Can the curly brackets { } be used to enclose a single line of code?

717


What are the loops in c?

597


What is default value of global variable in c?

564


What does do in c?

612


State the difference between realloc and free.

641


What is pointers in c with example?

585


Why functions are used in c?

592


Is c is a low level language?

568