| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 632 人关注过本帖
标题:[原创]学习c#自己写的程序,希望交流交流(会不定期更新)
只看楼主 加入收藏
hjl2006404
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-4
结帖率:50%
收藏
 问题点数:0 回复次数:2 
[原创]学习c#自己写的程序,希望交流交流(会不定期更新)
(1)打印乘法口诀表
四方形
using System;
namespace huangjin
{
    class Test
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <=9; i++)
            {
                for (int j = 1; j <=9; j++)
                {
                    Console.Write("{0}*{1}={2}\t",i,j,i*j);
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }      
    }
}
三角形
using System;
namespace huangjin
{
    class Test
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <=9; i++)
            {
                for (int j = 1; j <=i; j++)
                {
                    Console.Write("{0}*{1}={2}\t",i,j,i*j);
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }      
    }
}
  
收到的鲜花
  • 野比2010-10-06 20:53 送鲜花  3朵   附言:我很赞同
搜索更多相关主题的帖子: 定期 交流 学习 
2010-10-05 10:17
zwk199024
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:63
专家分:102
注 册:2010-9-15
收藏
得分:0 
恩。。。挺好
2010-10-05 11:08
hjl2006404
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-4
收藏
得分:0 
实现简单四则运算小程序
面向过程式的
using System;
using System.Collections.Generic;
using System.Text;
namespace huangjin
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入数字A:");
            string A = Console.ReadLine();
            Console.Write("请选择运算符号(+,-,*,/):");
            string B = Console.ReadLine();
            Console.Write("请输入数字B:");
            string C=Console.ReadLine();
            string D="";
            if(B=="+")
                D=Convert.ToString(Convert.ToDouble(A)+Convert.ToDouble(C));
            if(B=="-")
                D=Convert.ToString(Convert.ToDouble(A)-Convert.ToDouble(C));
            if(B=="*")
                D=Convert.ToString(Convert.ToDouble(A)*Convert.ToDouble(C));
            if(B=="/")
                D=Convert.ToString(Convert.ToDouble(A)/Convert.ToDouble(C));
            Console.WriteLine("结果是:"+D);
            Console.ReadKey();
        }
    }
}
面向对象的编程,不能提示除数为零的情况
using System;
using System.Collections.Generic;
using System.Text;

namespace DaHua1
{
   public class Operation
    {
       public static double GetResult(double numberA, double numberB, string operate)
       {
           double Result = 0d;
           switch (operate)
           {
               case"+":
                   Result = numberA + numberB;
                   break;
               case "-":
                   Result = numberA - numberB;
                   break;
               case "*":
                   Result = numberA * numberB;
                   break;
               case "/":
                   Result = numberA / numberB;
                   break;
           }
           return Result;
       }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace DaHua1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("请输入数字A:");
                string strNumberA = Console.ReadLine();
                Console.Write("请选择运算符号(+,-,*,/):");
                string strOperate = Console.ReadLine();
                Console.Write("请输入数字B:");
                string strNumberB = Console.ReadLine();
                string strResult = "";
                strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA),
                    Convert.ToDouble(strNumberB), strOperate));
                Console.WriteLine("结果是:"+strResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine("您的输入有错:" + ex.Message);
            }
            Console.ReadKey();
        }
    }
}
面对象的编程,能提示除数为零并且要求重新输入

using System;
using System.Collections.Generic;
using System.Text;

namespace DaHua1
{
   public class Operation
    {
       public static double GetResult(double numberA, double numberB, string operate)
       {
           double Result = 0d;
           switch (operate)
           {
               case "+":
                   Result = numberA + numberB;
                   break;
               case "-":
                   Result = numberA - numberB;
                   break;
               case "*":
                   Result = numberA * numberB;
                   break;
               case "/":
                     Result = numberA / numberB;
                   break;
           }
           return Result;
       }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace DaHua1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("请输入数字A:");
                string strNumberA = Console.ReadLine();
                Console.Write("请选择运算符号(+,-,*,/):");
                string strOperate = Console.ReadLine();
                while (true)
                {
                    Console.Write("请输入数字B:");
                    string strNumberB = Console.ReadLine();
                    string strResult = "";
                    if (strOperate != "/")
                    {
                        strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA),
                        Convert.ToDouble(strNumberB), strOperate));
                        Console.WriteLine("结果是:{0}" + strResult);
                        break;
                    }
                    else if (strNumberB != "0")
                    {
                        strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA),
                        Convert.ToDouble(strNumberB), strOperate));
                        Console.WriteLine("结果是:" + strResult);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("请检查除数的非零性,并再次输入");
                    }
                }
            }
            
            catch (Exception ex)
            {
                Console.WriteLine("您的输入有错:" + ex.Message);
            }
            Console.ReadKey();
        }
    }
}


2010-10-11 11:46
快速回复:[原创]学习c#自己写的程序,希望交流交流(会不定期更新)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018893 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved