做一个控制台程序,要求输入三个任意整数,将三个数按从大到小的顺序输出。
根据排列组合,知道有6中情况,一是可以采用排序,不过有些小题大做。二是可以交换,输出。
方法一
采用交换,让a最大,b第二大,就行了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" put into 3 numbers");
int a, b, c;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
display(a, b, c);
}
static void display(int a, int b, int c)
{
//保证a最大
if(a put into 3 numbers
55
88
111
111,88,55
请按任意键继续. . . 采用冒泡排序,搞定
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace homework1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" put into 3 numbers");
int a,b,c;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
Console.WriteLine("the array:");
int[] num = { a, b, c };
display(num);
sort(num);
Console.WriteLine(" sort the end");
display(num);
}
static void sort(int[] str)
{
for(int i=0; i put into 3 numbers
11
22
66
the array:
11
22
66
sort the end
66
22
11
请按任意键继续. . .
定义一个student的结构体,有姓名,分数属性,输入3组数据,在输出,并求出平均分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace homework3
{
class Program
{
struct Student
{
public string name; //姓名
public float math; //数学成绩
}
static void Main(string[] args)
{
Student[] s = new Student[4];
s= input(s);
display(s);
// double ave = s[0].math + s[1].math + s[2].math;
float ave = s[s.Length - 1].math;
Console.WriteLine("the average mark is :" + ave/3);
Console.WriteLine();
}
static Student[] input(Student[] s)
{
float sum = 0;
for(int i=0; i 结果是:
put 1 student name and mark:
a
85
put 2 student name and mark:
b
90.5
put 3 student name and mark:
c
76.5
a的数学成绩是:85
b的数学成绩是:90.5
c的数学成绩是:76.5
的数学成绩是:252
the average mark is :84 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/430/viewspace-2808795/ ,如需转载,请注明出处,否则将追究法律责任。