zoukankan      html  css  js  c++  java
  • 判断是否为质数(素数)

            private static void isPrime(int i)
            {
                
    bool IsPrime = true;
                //Console.WriteLine(Math.Sqrt(i));
                
    for (int j = 2; j <= Math.Sqrt(i); j++)
                {
                    
    if (i % j == 0)
                    {
                        IsPrime 
    = false;
                        
    break;
                    }
                }
                
    if (IsPrime)
                {
                    Console.WriteLine(
    "我是素数。");
                }
                
    else
                {
                    Console.WriteLine(
    "我是合数。");                                
                }                               
            }
  • 相关阅读:
    5个排序算法
    原生侧边栏sidebar
    静态方法、实例方法、继承
    函数作用域之闭包与this!
    OOP面向对象编程(下)
    数组方法篇二
    对象
    nginx windows负载均衡入门
    NVelocity
    python3简单爬虫
  • 原文地址:https://www.cnblogs.com/wpsl5168/p/1654163.html
Copyright © 2011-2022 走看看