prime.cpp

来自「经常使用的一些源程序.包括一些模板.在VC++6.0下通过.」· C++ 代码 · 共 61 行

CPP
61
字号
#include <iostream>
using namespace std;

/*main information*/
void info()
{
	cout << "prime number";
	cout << endl << endl;
}

/*judge if x is a prime number*/
bool prime(int judge_x)
{
	if (judge_x < 2){return false;}
	else
	{
		for (int i = 2; i < judge_x / 2 + 1; i++)
		{
			if (judge_x % i == 0)
			{
				return false;
			}
		}
		return true;
	}
}

/*source code*/
void test()
{
	for (int i = 0; i < 1000; i++)
	{
	if(prime(i))
	{
		cout << i <<"\t"; //<< " is prime number.\n";
	}
	else
	{
//		cout << i << " is not prime number.\n";
	}
	}
}

/*information of source code owner*/
void end()
{
	cout << "\n\n\n______________\n";
	cout << "xiao zhiqiang\n";
	cout << "inxk@163.com\n";
	cout << "Sep,2006";
	getchar();
}

/*the main code*/
void main()
{
	info();
	test();
	end();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?