Determine and output a prime number between 101-200

Source: Internet
Author: User
Tags printf

See the full set of "C language problem sets"

Title: Determine how many primes there are between 101-200, and output all primes.

1. Procedure Analysis:

The method of determining primes: To remove 2 to sqrt (this number) by a number, if divisible, indicates that the number is not prime, and vice versa.

2. Program Source code:

#include "stdio.h"
#include "conio.h"
#include "math.h"
Main ()
{
int m,i,k,h=0,leap=1;
printf ("\ n");
for (m=101;m<=200;m++)
{
K=SQRT (m+1);
for (i=2;i<=k;i++)
if (m%i==0)
{
Leap=0;
Break
}
if (LEAP)
{
printf ("%-4d", m);
h++;
if (h%10==0)
printf ("\ n");
}
Leap=1;
}
printf ("\nthe total is%d", h);
Getch ();
}

3.Visual C + + 6.0 debugging pass, as shown in figure:

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.