C#控制台应用程序

1.打印*****

          ****

          ***

          **

          *(for循环)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;                                        // 定义两个变量
            for (a = 1; a <= 5; a++)           //一个变量控制层数
            {
                for (b = 5; b >= a; b--)         //一个变量控制输出*的个数
                {
                    Console.Write("*");         //打印*
                }
                Console.WriteLine();          //换行
            }
        }
    }
}
 

2.打印*

          **

          ***

          ****

          *****(for循环)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;                                           //定义两个变量
            for (a = 1; a <= 5; a++)              //一个变量控制层数
            {
                for (b = 1; b<= a; b++)           //一个变量控制输出*个数
                {
                    Console.Write("*");            //输出*
                }
                Console.WriteLine();             //换行
            }
        }
    }
}

3.打印数阵

          1 2 3

          1 2 3

          1 2 3(for循环)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            int y;
            for (x = 1; x <= 3; x++)           // 循环变量行号
            {
                for (y = 1; y <= 3; y++)        //循环变量列号
                {
                    Console.Write(y);           //第一行输出列号
                    Console.Write(" ");         //输出空格隔开
                }
                Console.WriteLine();          //换行
            }
        }
    }
}

4.打印数阵

          11  12  13

          21  22  23

          31  32  33(for循环,运用占位符)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            int y;
            for (x = 1; x <= 3; x++)                     // 循环变量行号
            {
                for (y = 1; y <= 3; y++)                 //循环变量列号
                {
                    Console.Write("{0}{1}",x,y);      //占位符输出行号和列号
                    Console.Write(" ");                   //输出空格隔开
                }
                Console.WriteLine();                    //换行
            }
        }
    }
}

5.计算方程x*x+y*y+2*x*y=25,x和y的值(for循环,运用占位符输出)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            int y;                                                                            //定义两个变量(未知数)
            for (x = 1; x <= 25; x++)                                              //x的取值范围
            {
                for (y = 1; y <= 25; y++)                                          //y的取值范围
                {
                    if (x * x + y * y + 2 * x * y == 25)                         //方程等式的结果
                    {
                        Console.WriteLine("x={0},y={1}", x, y);          //输出x,y分别的值
                    }
                }
               
            }
        }
    }
}

6.计算三个一位整数a,b,c分别作为个位十位百位,abc,cba相加等于1333(for循环,运用占位符输出)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c;                                                                        //定义三个变量
           
            for (a = 1; a <= 9; a++)                                                 //第一个未知数的取值
            {
                for (b = 1; b <= 9; b++)                                             //第二个未知数的取值
                {
                    for (c = 1; c <= 9; c++)                                         //第三个未知数的取值
                    { 
                     if(a*100+b*10+c+c*100+b*10+a==1333)           //判断相加等于值
                      {
                        Console.WriteLine("a={0},b={1},c={2}",a,b,c);  //输出a,b,c的值
                      }
                    }
                }
            }
        }
    }
}
 

7.在主方法同一个类中,判断两个数的奇偶性(方法)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
           JiOuShu(6);

        }

        static void JiOuShu(int x) 
        {
            if (x%2==0)
            {
                Console.WriteLine("{0}是偶数", x);
            }
            else
            {
                Console.WriteLine("{0}是奇数", x);
            }
           
        }
    }
}

7.在主方法同一个类中,输入两个数求和(方法)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ketang
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, y;                                                           //定义两个变量
            x = int.Parse(Console.ReadLine());               //输入第一个变量的值
            y = int.Parse(Console.ReadLine());              //输入第二个变量的值
            QiuHe(x, y);                                                 //存入定义的'QiuHe'里面

        }
        static void QiuHe(int x,int y) 
        {

            Console.WriteLine("{0}加{1}等于{2}",x,y,x+y);         //输出结果
           
        }
    }
}
 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值