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

c#小练习ⅰ

2016-09-15 12:46 344 查看

使用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);
}
}
}


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息