Get Started: +91 800-114-6000 / +91 947-453-0936
This is an Important Announcement. Please go through our website regularly for all Announcements.
MENU

Check a number is prime or not
Programming Logics 06 Jul,2016 0


The simplest primality test is trial division: Given an input number n, check whether any prime integer m from 2 to n/2 evenly divides n (the division leaves no remainder).


int main(){    
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d",&n);

for(i=2; i<=n/2; ++i)
{
// condition for nonprime number
if(n%i==0)
{
flag=1;
break;
}
}

if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);

return 0;
}


Comments:
Sorry! No comment present till there, Be the First person to post a Comment.


Leave a Reply
Your email address will not be published. Required fields are marked *
Name *
Email *
Website
Comment *
You may use these HTML tags and attributes: <b> <i> <strong>
About FlexonLabs::
You have reached one of life's important cross roads. You are about to leave college life behind to embark upon your professional career. We understand that, for you, it is a time for important decisions and you undoubtedly want to know how to realize your full potential. At Flexon, we appreciate that everyone has different needs; your goals and interests are wide and varied. With your future so full of possibilities, we encourage you to explore your options fully before making any big decisions.
Social Bookmarks:
FlexonLabs [ A Unit of Flexon Technologies Limited ]
A/27, Armstrong Avenue, Bidhannagar, Durgapur, West Bengal -713212
Phone No: +91 800-114-6000 / +91 947-453-0936
Email Id: Flexonlabs2010@Gmail.Com, Info@Flexonlabs.Com
Navigation
ProfileCoursesGlobal CertificationScholarshipPlacementFranchiseContactsDownloadsNoticeBoardEventsSeminarBoot Camp

Visitor: 89070
All Rights Reserved by FlexanLabs | Designed & Developed by Flexon Technologies Limited