求0-100所有的质数

来源:百度知道 编辑:UC知道 时间:2024/06/25 00:09:46
用c#编写
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
我想用这个判断出里面的质数

// 质数.cpp
// Using the Array to calculate them from 1 to 100
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
int a[ 101 ] = { 0 };

for ( int i = 3; i <101; i++ )
{
for (int j = 2; j < ( i/2 + 1 ); j++ )
{
if ( i % j == 0 ) {
a[ i ] = 1;
}
}
}
for ( int i = 2; i < 101; i++ )
{
if ( a[ i ] == 0 )
{
cout << " " << i << " ";
}
}
cin.get();
return 0;
}

c