c#小练习ⅰ

使用VisualStudio编写控制台应用程序
从命令行输入半径,求对应的圆的周长、面积

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Class1
    {
       static void Main(string[] args)
       {
           Console.WriteLine("输入圆的半径:");
           int a = int.Parse(Console.ReadLine());
           Console.WriteLine("圆的周长为:" + 2 * a * 3.14);
           Console.WriteLine("圆的面积为:" + 3.14 * a * a);
       }
    }
}


 

使用VisualStudio编写控制台应用程序
从命令行读入三角形的三条边,判断是否可以构成三角形,如果可以,求三角形的周长

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 三角形
{
    class Program
    {
        staticvoid Main(string[] args)
       {
           Console.WriteLine("输入三角形三边:");
           int[] a = { 0, 0, 0 };
           for (int i = 0; i < 3; i++)
           {
               a[i] = int.Parse(Console.ReadLine());
           }
           if (a[0] + a[1] > a[2] && a[0] + a[2] > a[1] && a[1] +a[2] > a[0])
           {
               Console.WriteLine("能够构成三角形");
           }
           else
           {
               Console.WriteLine("构不成三角形!!");
               return;
           }
           Console.WriteLine("三边为:");
           for (int i = 0; i < 3; i++)
           {
               Console.WriteLine(a[i] + " ");
           }
       }
    }
}


 

使用VisualStudio编写控制台应用程序
从命令行读入三个整数,求三个整数的最大值
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace abc_compar
{
    class Program
    {
       static void Main(string[] args)
       {
           Console.WriteLine("输入三个数字:");
           int a = int.Parse(Console.ReadLine());
           int b = int.Parse(Console.ReadLine());
           int c = int.Parse(Console.ReadLine());
           int d = (a > b ? a : b);
           Console.WriteLine(c>d?c:d);
       }
    }
}
 


使用VisualStudio编写控制台应用程序
有一函数,编写一个程序,从键盘输入一个x 值,程序输出y 的值

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace fun____
{
    class Program
    {
       static void Main(string[] args)
       {
           Console.WriteLine("输入一个数:");
 
           while (true)
           {
               int a = int.Parse(Console.ReadLine());
               if (a > 0)
               {
                   Console.WriteLine(-1 + 3 * a);
               }
               else if (a < 0)
               {
                   Console.WriteLine(-1 + 2 * a);
               }
               else if (a == 0)
               {
                   Console.WriteLine("-1");
               }
 
           }
 
       }
    }
}


使用VisualStudio编写控制台应用程序
输出1-100 中能被3 整除但不能被5 整除的数,并统计这样的数有多少个

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace _1_100
{
    class Program
    {
       static void Main(string[] args)
       {
           int num = 0;
           for (int i = 0; i <= 100; i++)
           {
               if (i % 3 == 0 && i % 5 != 0)
               {
                   num++;
                   Console.Write(" " + i);
               }
           }
           Console.WriteLine();
           Console.WriteLine("能被3整除不能被5整除的数字共有:" + num);
       }
    }
}
 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值