Using the filter method to find the prime number within 100 (array)

Source: Internet
Author: User

Using the filter method to find the prime number within 100, the use of arrays is required.


#include "stdafx.h"
#include <iostream>
using namespace Std;


int _tmain (int argc, _tchar* argv[])
{
int a[100],i,b[100],j,n=0; Array a[100] To put in the number of judgements, array b[100] to place prime numbers
for (i=0;i<100;i++)//Note here I cannot start from 1 because the first of array A is a[0]
{
a[i]=i+1; The number in a[100] is from 1 to 100.
}
for (i=2;i<=100;i++)//0 and 1 do not judge
{
for (j=2;j<i;j++)
{
if (i%j==0)
{
Break If I can divide any number from 2 to i-1, then I is not a prime, jumping out of the loop
}
if (j==i-1)//If the above conditions have not been established, then j=i-1 after the end of the cycle, I is the prime number
{
B[n]=i;
n++; Put I in order in the array b[100]
}
}
}


for (i=0;i<n;i++)
{
cout<<b[i]<<endl; The number stored in the output array B, in turn
}
return 0;
}

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

Using the filter method to find the prime number within 100 (array)

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.