zoukankan      html  css  js  c++  java
  • code天天写代码重新出发

    //Prime Number Test
    public class Test{   
        public static void Main(){
            try{
                PrintPrime(100,400);
            }catch(System.Exception ex){
                System.Console.WriteLine(ex.Message);
            }
        }
        //print prime number between low and High
        static void PrintPrime(int low, int high){
            string strErrMsg = "";
            if(low < 0 || high< 0){       
                strErrMsg = "Natural number must be 1+ integer!";
                throw new System.ArgumentOutOfRangeException("",strErrMsg);
            }
            if(high > int.MaxValue || low < int.MinValue){           
                strErrMsg = "Integer Value is out of range !";
                throw new System.ArgumentOutOfRangeException("",strErrMsg);
            }
            int ix = low;
            for (;ix <= high; ix++){
                if(IsPrime(ix)){
                    System.Console.Write(ix + "\t");
                }
            }
        }
        // Is it a prime number     
        // returns : ture, is prime number
        //         : false,is not prime number       
        static bool IsPrime(int n){
            bool blnReturn = true;
            if (n <= 1){
                blnReturn = false;
            }
            for(int i=2; i<Sqrt(n); i++){
                if ( n % i == 0){
                    blnReturn = false;
                    break;
                }
            }
            return blnReturn;
        }
        //my Sqrt
        static double Sqrt(double num ){
            double E = 0.0000001f;
            double d = num /2;
            while (Abs(num - d * d) > E){
               d = (d + num / d) / 2;
            }
            return d;
        }    
        //my Abs
        static double Abs(double d){
            if ( d >= 0) {
                return d;
            }
            else{
                return -d;
            }
        }
    }

  • 相关阅读:
    微信小程序使用canvas画布实现当前页面截屏并分享
    微信小程序分享转发用法大全——自定义分享、全局分享、组合分享
    小程序条形码插件wxbarcode的使用及改进
    支付宝小程序开发——修改小程序原生radio默认样式
    常用maven配置
    Android Studio 星云常用配置工具箱
    星云最佳实践功法秘籍
    Intellij Idea 星云常用配置工具箱
    那些好用的Chrome 插件
    星云的Linux专用学习手册
  • 原文地址:https://www.cnblogs.com/qinghao/p/1541216.html
Copyright © 2011-2022 走看看