马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C#练习

[复制链接]
查看4484 | 回复3 | 2013-12-15 15:16:01 | 显示全部楼层 |阅读模式
[AppleScript] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//重复让用户输入输入一个数,判断该数是否质数,当输入“q”时,程序运行结束!(质数的判断要求用方法来实现)。
namespace 平时练习
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("please input a num:");
            string numberstring = Console.ReadLine();
            while (numberstring != "q")
            {
                int numint = Convert.ToInt32(numberstring);
                bool result = Panduan(numint);
                if (result == true)
                    Console.WriteLine("{0}is zhishu", numint);
                else
                    Console.WriteLine("{0} is not zhishu",numint);
                Console.WriteLine("please input a num:");
                numberstring= Console.ReadLine();
                Console.ReadKey();
            }

        }

        private static bool Panduan(int numint)
        {
            bool result = true;
            double x = Math.Sqrt(numint);
            for (int i = 2; i <= x;i ++ )
            {
                if (numint % i == 0)
                {
                    result = false; break;
                }
            }
            return result;
        }
    }
}

ibcadmin | 2013-12-15 19:07:18 | 显示全部楼层
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
devilq0129 | 2013-12-17 09:12:26 | 显示全部楼层
新人来参考
东方 | 2013-12-25 08:36:29 | 显示全部楼层
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则