c#判断一个数是否是素数
范伟伟
素数是只能被1或本身整除,且不能为其他两个整数的乘积。1、2、3本身就是素数,判断一个数是否为素数,只需要用这个值依次除以2到它的开方数,如果其中有一个数可以整除,那么该值不为素数,返之为素数。代码如下
publicboolprimeNumber(intn)
{
boolb=true;
if(n==1||n==2)
b=true;
else
{
intsqr=Convert.ToInt32(Math.Sqrt(n));
for(inti=sqr;i>2;i--)
{
if(n%i==0)
{
b=false;
}
}
}
returnb;
}
相关文档:
C#与Flash交互 (转自小磊在线)
C#与Flash交互
前段日子公司要求做一个C#与Flash交互的东西,用来C#与短信猫通讯将数据传到Flash上显示与操作的应用。
第一步C#添加组件
打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定
添加好组件往场景上拖放,如果提示注册需求注册
c# 注册控件-在运行输 ......
在net中有一个至关重要的关键字,那就是using
using一般有着以下几种用法:
1、直接引入命名空间
a、using System ,这个是最常用的,就是using+命名空间,这样就可以直接使用命名空间中的类型,而免去了使用详细的命名空间
b、使用全限定名
不用使用using System;直接在程序中调用System.Console.WriteLine("Hello ......
public struct RECT
{
public int left;
public int Top;
public int Right;
public int Bottom;
}
public static bool CenterMouseOn(int hwnd)
{
......
public struct POINTAPI
{
public int x;
public int y;
}
public static void GetWindowfromPoint(ref int hwnd,ref StringBuilder winText,ref StringBuilder clsName,ref StringBuilder pText)
{
int parentHandle=0;
int maxLen=128;
POINTAPI pnt = new ......