C#基础第一天-作业答案

时间:2021-07-08 15:57:11
题一答案:

      Console.WriteLine("请输入a");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入b");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入c");
int c = Convert.ToInt32(Console.ReadLine());
int max = ;
写法一
max = a > b ? a : b;
max = max > c ? max : c;
Console.WriteLine("最大的数为" + max);
Console.ReadKey();
写法
if (a > b)
{
max = a;
}
else if (b > a)
{
max = b;
}
if (max > c)
{
Console.WriteLine("最大的数为" + max);
}
else
{
Console.WriteLine("最大的数为" + c);
}
Console.ReadKey();
写法三
if ((a > b) && (a > c))
{
Console.WriteLine("最大的数为" + a);
}
else if ((b > c) && (b > a))
{
Console.WriteLine("最大的数为" + b);
}
else if ((c > b) && (c > a))
{
Console.WriteLine("最大的数为" + c);
}
Console.ReadKey(); 题二答案: Console.WriteLine("请输入d");
int d = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入e");
int e = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入f");
int f = Convert.ToInt32(Console.ReadLine());
int min = ;
写法一
min = d < e ? d : e;
min = min < f ? min : f;
Console.WriteLine("最小的数为" + min);
Console.ReadKey();
写法二
if (d < e)
{
min = d;
}
else if (e < d)
{
min = e;
}
if (min < f)
{
Console.WriteLine("最小的数为" + min);
}
else
{
Console.WriteLine("最小的数为" + f);
}
Console.ReadKey();
写法三
if ((d < e) && (d < f))
{
Console.WriteLine("最小的数为" + d);
}
else if ((e<d ) && (e<f))
{
Console.WriteLine("最小的数为" + e);
}
else if ((f<e ) && (f <d))
{
Console.WriteLine("最小的数为" + f);
}
Console.ReadKey(); 第三题答案: Console.WriteLine("请输入您的成绩");
double score = Convert.ToDouble(Console.ReadLine());
if (score >= )
{
Console.WriteLine("考的很好,您的成绩为优");
}
else if (score >= && score < )
{
Console.WriteLine("好不错呦,您的成绩为良");
}
else if (score >= && score < )
{
Console.WriteLine("请继续努力,您的成绩为中");
}
else if (score >= && score < )
{
Console.WriteLine("好危险啊,您的成绩刚刚及格");
}
else
{
Console.WriteLine("好好学习吧,您还没及格");
}
Console.ReadKey(); 第四题答案: Console.WriteLine("请输入您的成绩");
int result = Convert.ToInt32(Console.ReadLine());
string mark=string.Empty;
if (result >= && result <= )
{
mark = "优秀";
}
if (result >= && result <= )
{
mark = "良好";
}
if (result >= && result <= )
{
mark = "及格";
}
if (result <= )
{
mark = "不及格";
}
switch (mark)
{
case "优秀":
Console.WriteLine("您的成绩为优秀");
break;
case "良好":
Console.WriteLine("您的成绩为良好");
break;
case "及格":
Console.WriteLine("您的成绩为及格");
break;
case "不及格":
Console.WriteLine("您的成绩不及格");
break;
}
Console.ReadKey(); 第五题答案: //第一种
int a = , b = ;
int change = a;
a = b;
b = change;
Console.WriteLine("a={0},b={1}",a,b);
Console.ReadKey(); //第二种
int a = , b = ;
b = a + b;
a = b - a;
b = b - a;
Console.WriteLine("a" + a);
Console.WriteLine("b" + b);
Console.Read();

本系列教程:

C#基础总结之八面向对象知识点总结-继承与多态-接口-http://www.cnblogs.com/spring_wang/p/6113531.html

C#基础总结之七面向对象知识点总结1http://www.cnblogs.com/spring_wang/p/6113526.html

C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习http://www.cnblogs.com/spring_wang/p/6113520.html

C#基础总结之五Dictionary<string, string[]>和while循环http://www.cnblogs.com/spring_wang/p/6113514.html

C#基础总结之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html

C#基础总结之三循环控制-for-数组-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html

C#基础总结之二循环控制-运算符http://www.cnblogs.com/spring_wang/p/6113484.html

C#基础总结之一变量常量-if嵌套语句-witch结构-类型转换http://www.cnblogs.com/spring_wang/p/6113476.html

C#基础课程之六(临时表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html

C#基础课程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html

C#基础课程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html

C#基础课程之三循环语句http://www.cnblogs.com/spring_wang/p/6113383.html

C#基础课程之二变量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html

C#基础课程之一注释和控制台、一些常识http://www.cnblogs.com/spring_wang/p/6113361.html

C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html

C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html

C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113274.html

C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113258.html

C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113232.html

C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113224.html

C#基础第六天-作业-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113028.html

C#基础第六天-作业答案-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113033.html

C#基础第五天-作业答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html

C#基础第五天-作业-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html

C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113005.html

C#基础第四天-作业-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113000.html

C#基础第三天-作业答案-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112888.html

C#基础第三天-作业-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112885.html

C#基础第二天-作业答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html

C#基础第二天-作业-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html

C#基础第一天-作业答案http://www.cnblogs.com/spring_wang/p/6112872.html

C#基础第一天-作业http://www.cnblogs.com/spring_wang/p/6112867.html

C#-string.Format对C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html