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

Write a program to swap two numbers without using the third variable?

597


Explain About fork()?

647


What is structure padding in c?

628


What are the 3 types of structures?

572


What is union in c?

637






How can I read and write comma-delimited text?

621


When do we get logical errors?

637


Write the Program to reverse a string using pointers.

617


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

636


Why is c so popular?

650


Explain how do you view the path?

655


How can I remove the trailing spaces from a string?

616


What is int main () in c?

627


to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?

1573


What is a good data structure to use for storing lines of text?

597