c#練手code
做一個控制檯程式,要求輸入三個任意整數,將三個數按從大到小的順序輸出。
根據排列組合,知道有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部落格 ” ,連結:http://blog.itpub.net/430/viewspace-2808795/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Autodesk View and Data API練練手ViewAPI
- c# 練習總結C#
- C# Code SummaryC#
- Spring aop練手Spring
- gin練手專案
- 前端練手專案前端
- LeetCode練習-中等卷LeetCode
- Python練手例子(16)Python
- Python練手例子(14)Python
- Python練手例子(13)Python
- Python練手例子(6)Python
- web 練手 JavaScript 輸出WebJavaScript
- C# Unicode編碼C#Unicode
- ThinkPHP3.2練手網站PHP網站
- Flutter練手專案--玩安卓Flutter安卓
- 前端練手專案小結前端
- 簡單練手APP《每閱》APP
- C# 多工網段掃描練習C#
- 學習 golang 中,寫了個 golang http client 練練手GolangHTTPclient
- YT14-先來練練手之絕對值排序排序
- flutter 練手之優雅的開車Flutter
- web前端佈局練手專案Web前端
- Vue練手專案(包含typescript版本)VueTypeScript
- 10個Python練手專案Python
- TreeView.cs source code in C# .NETViewC#
- leetcode 593. Valid Square練習LeetCode
- leetcode 593. Valid Square 練習LeetCode
- nowcoder 牛客練習賽9 B
- C#練習,應用for,while,do-while迴圈C#While
- go+vue入門專案練手GoVue
- asp.net(C#) 編碼解碼(HtmlEncode與HtmlEncode)ASP.NETC#HTML
- codesoft在delphi,C#中的例子C#
- LintCode/LeetCode訓練題目&答案詳解—基礎篇LeetCode
- C# 手寫識別方案整理C#
- LeetCode演算法訓練-回溯總結LeetCode演算法
- 一棵韭菜的自我修養:用Python分析下股市,練練手Python
- Flutter 1.12 個人練手學習小案例Flutter
- Python練手題,敢來挑戰嗎?Python