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); } } }
相关文章推荐
- C#练习代码
- 从明天开始把以前的学过的算法代码用C#都练习下,
- C# 语法练习(9): 类[一] - 访问限制、方法、字段、属性
- c# 字符串常用函数练习
- c#字符处理小练习
- asp.net(C#) Xml操作(增删改查)练习
- C# 语法练习(10): 类[二] - 继承、覆盖、多态、隐藏
- C# 语法练习(14): 类[六] - 事件
- [c#]关于双缓冲绘图的练习
- [C#]练习了下数组和类,C++ 基础还算可以,不是很吃力
- C# 语法练习(2): 字符转义
- C# 语法练习(6): 枚举
- C# 语法练习(8): 函数
- C# 语法练习(3): 运算符
- [C#]写个记事本作为 Windows 程序的练习,这个是雏形
- 做练习时写了一个调用DOS命令删文件夹及子目录和文件的C#程序
- C# 语法练习(1): 基本数据类型
- C# 语法练习(11): 类[三] - 构造函数、析构函数、base、this
- 菜鸟练习C#htmlparser----C#正则加htmlDOM进行网页解析腾讯新闻帖子列表相关信息提取
- 菜鸟学习C#数据库实例练习使用SqlDataReader,SqlCommand SqlConnection