C language Function Call 09-Determine whether a number is a prime

Source: Internet
Author: User

Function call
/*
==========================================================
Title: Judge whether a number is a prime. If 3 is a prime number, 4 is not a prime number.
==========================================================
*/
#include <stdio.h>
#include <stdlib.h>
int Sushu (int n)
{
int i,k;
k=n/2;//Control End Position!
for (i=2;i<=k;i++)
if (n%i==0) break;
if (i>k) return 1;
else return 0;
}
void Main ()
{
int n,flag=1;
while (flag)
{
printf ("Please enter judgment number: \ n");
scanf ("%d", &n);
System ("CLS");
if (Sushu (n))
printf ("%d is a prime number!") \ nthe ", n);
Else
printf ("%d is not a prime number!") \ nthe ", n);
}
System ("CLS");
}


/*
==========================================================
Comment: First write the function of prime number, is returns 1, no return 0, and then call the function to judge continuously.
==========================================================
*/



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C language Function Call 09-Determine whether a number is a prime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.