7.28号C#作业
2010-09-12 08:17
260 查看
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();
}
}
}
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();
}
}
}
相关文章推荐
- 人工智能作业——八数码问题 BFS+A* C# WindowsFormApplication
- C#窗体随机四则运算 (第四次作业)
- 【C#基础】【语法03】课后作业题 01-06
- 【c#第六次作业】猜猜看游戏
- C#作业qt做的随机图片显示t
- c#作业
- C#第七次作业:学习总结
- C# 第七次作业
- C#第七次作业(WPF&XAML)
- 一个C#的学生成绩管理系统作业
- C#小作业 换算
- C#大作业一个简单的编辑器
- 第四次C#作业-MySQL数据库及C#操作MySQL数据库
- 第四次作业:MySQL数据库及C#操作MySQL数据库
- lwj_C#_作业
- C#第五次作业:开源项目“网页正文提取”的理解
- 【c#第五次作业】测试 Html2Article 并添加保存功能
- C#第五次作业:开源项目“网页正文提取”的理解
- C#第一次作业,C#或者java代码总行数、代码行数、代码空格行数、注释行数的统计
- 暑期总结之--c#界面设计作业Mini U-NET(多图杀猫)