7.28号C#作业
来源:互联网 发布:人工智能工作原理 编辑:程序博客网 时间:2024/06/09 16:22
1 、三角形等边 返回 1 等腰 2 其他返回3 不能构成三角形 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sanjiaoxing
{
// 三角形 等边 返回 1 等腰 2 其他返回3 不能构成三角形 4
class Program
{
static void Main(string[] args)
{
int sum;
Console.WriteLine("请分别输入三角形的三条边");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int c = int.Parse(Console.ReadLine());
if (!(a + b > c || a + c > b || b + c > a))
{
Console.WriteLine("输入的三条边无法构成三角形");
sum = 4;
}
else
{
if (a == b&&b == c)
{
sum = 1;
Console.WriteLine("所输入的三条边构成的是等边三角形");
}
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
{
sum = 2;
Console.WriteLine("所输入的三条边构成的是等腰三角形");
}
else
{
sum = 3;
Console.WriteLine("所输入的三条边构成的是普通三角形");
}
}
Console.WriteLine("返回的值是{0}", sum);
Console.ReadLine();
}
}
}
2 、狗年龄
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DogAge
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入狗的年龄!");
int age = int.Parse(Console.ReadLine());
int[] arr = new int[20];
arr[0] = 17;
arr[1] = 23;
arr[2] = 28;
for (int i = 3; i < arr.Length; i++)
{
arr[i] = arr[i-1] + 4;
}
Console.WriteLine("狗相对于人的年龄是:{0}", arr[age-1]);
}
}
}
3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace diguiDemo
{
//一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Digui(30));
Console.ReadLine();
}
static int Digui(int t)
{
if (t <= 0)
{
return 0;
}
else if (t <= 2)
{
return 1;
}
else
{
return Digui(t - 2) + Digui(t - 1);
}
}
}
}
4.请编程实现一个冒泡排序算法?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace maopao
{
//数组排序
class Program
{
static void Main(string[] args)
{
int[] arr1 = new int[] { 12, 4, 22, 5, 9, 36, 7, 14, 2, 18 };
Console.WriteLine("数组排序前");
foreach (int n in arr1)
Console.Write(n + " ");
Console.WriteLine();
int j, temp;
for (int i = 0; i < arr1.Length - 1; i++)
{
j = i + 1;
aa:
if (arr1[i] > arr1[j])
{
temp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = temp;
goto aa;
}
else
if (j < arr1.Length - 1)
{
j++;
goto aa;
}
}
Console.WriteLine("数组冒泡排序后");
foreach (int n in arr1)
Console.Write(n + " ");
Console.WriteLine();
}
}
}
- 7.28号C#作业
- C#作业
- c#作业
- c#作业
- [C#作业]
- C#作业
- c#作业
- C#作业
- c#实验6作业
- [c#作业] 9.24
- [c#作业]子窗口
- C#作业(第一次)
- C# 第一次作业
- C#小作业 换算
- C#作业2.
- c#小作业 三角形
- C#第四周作业
- c#第一次作业
- Windws XP Mode
- SQL Server2005,在windows验证情况下,C#连接sql数据库出错
- 安装sql 2005时出现计数器错误如何解决
- 安装SQL Server 2005时出现COM+的警告/错误解决方案
- Convert.ToInt32、(int)和int.Parse三者的区别
- 7.28号C#作业
- 双倍超立方数
- C#声明一个100大小的数组 随机生成1-100之间不重复的数
- 输入1-10000的素数
- 九九乘法表代码
- How to: Store and Reuse Queries (LINQ to SQL)
- 求从键盘上输入10个数据(实数)中的最大值,并求和
- SQL作业一
- SQL作业二