您的位置:首页 > 编程语言 > C#

c#关于输入一个整数是否为质数的代码

2016-08-07 16:35 183 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 质数

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("输入一个正整数");

            int a = Convert.ToInt32(Console .ReadLine());

            if (a == 1 || a == 2 || a == 3 || a == 5 || a == 7)

            {

                Console.WriteLine("是质数");

            }

              else   if ((a%2==0||a%3==0||a%5==0||a%7==0)&&(a !=1|| a != 2 || a != 3 || a != 5 || a!= 7))

            {

                Console.WriteLine("不是质数");

            }

            else

            {

                Console.WriteLine("是质数");

            }

            Console.ReadKey();

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# 质数
相关文章推荐