C#Lesson04

using System;


namespace Lesson04
{
class MainClass
{
public static void Main (string[] args)
{
// int[] intArr = { 8, 2, 9, 10, 11, 13, 17 };
// // 冒泡排序
// // int t;
// // for (int i = 0; i < intArr.Length -1 ; i++) {
// // bool flag = false;
// // for (int j = 0; j < intArr.Length-1 -i ; j++) {
// // if (intArr [j] > intArr [j+1]) {
// // t = intArr [j];
// // intArr [j] = intArr [j+1];
// // intArr [j+1] = t;
// // flag = true;
// // }
// // }
// // if (flag == false) {
// // break;
// // }
// // }
// // for (int i = 0; i < intArr.Length; i++) {
// // Console.WriteLine (intArr[i]);
// // }
// // 选择排序
// // int min;
// // int minIndex;
// // for (int i = 0; i < intArr.Length ; i++) {
// // min = intArr [i];
// // minIndex = i;
// // for (int j = i + 1; j < intArr.Length ; j++) {
// // if (min > intArr[j]) {
// // min = intArr [j];
// // minIndex = j;
// // }
// // }
// // intArr [minIndex] = intArr [i];
// // intArr [i] = min;
// // }
// // for (int i = 0; i < intArr.Length; i++) {
// // Console.WriteLine (intArr[i]);
//
//
// // int[] arr = { 3, 5, 1, 7, 9, 10, 16 };
// //选择排序(Selection Sort)
// // int min;
// // int minIndex;
// // for (int i = 0; i < arr.Length; i++)
// // {
// // min = arr[i];
// // minIndex = i;
// // //比较 i索引后的元素,找出最小值
// // for (int j = i + 1; j < arr.Length; j++)
// // {
// // if (min > arr[j])//找到了
// // {
// // min = arr[j];
// // minIndex = j;
// // }
// // }
// //交换
// //int temp = arr[i];
// //arr[i] = arr[minIndex];
// //arr[minIndex] = temp;
// // arr[minIndex] = arr[i];
// // arr[i] = min;
// }
//
// //二分查找
// // int low = 0;
// // int high = arr.Length - 1;
// // int target = 9;
// // while (high >= low) {
// // int midIndex = (low + high) / 2;
// // int mid = arr [midIndex];
// // //比较中间值和目标值
// // if (mid == target) {
// // Console.WriteLine ("找到目标值{0}", midIndex);
// // break;
// // } else if (mid < target) {
// // //将low低位索引移动到mid后面一位
// // low = midIndex + 1;
// // } else { //mid > target
// // //将high高位索引移动到mid前一位
// // high = midIndex - 1;
// // }
// // //比较 high 和 low的大小
// // if (high < low) {
// // Console.WriteLine ("没有查到{0}",target);
// // }
// // }
//
// //二维数组
// //定义二维数组
// //int[] a = new int[10]
// // int[,] socres = new int[3,20];
// // int[,] scores = new int[3, 4] {
// // { 1, 2, 3, 4 },
// // { 5, 6, 7, 8 },
// // { 9, 10, 11, 12 },
// // { 13, 14, 15, 16 }
// // };
// //            int[,] scores = 
// // new int[,] {{1,2,3,4},{ 9, 10, 11, 12 },}
//
// //     int[,] scores = 
// // new int[,] {{1,2,3,4},{ 9, 10, 11, 12 },}
//
// //     int[,] scores = new int[,]{
// // { 1, 2, 3, 4 },
// // { 5, 6, 7, 8 },
// // { 9, 10, 11, 12 },
// // { 13, 14, 15, 16 }
// // };
// // int length =  scores.Length;
// // Console.WriteLine (length);


// int[,] scores = 
// new int[,] { { 1, 2, 3, 4 }, { 2, 3, 4, 6 }, { 3, 6, 8, 9 } };
// int row = scores.GetLength(0);
// int column = scores.GetLength(1);


// int[,] a = new int[,] {
// { 1, 2, 3 },
// { 4, 5, 6 },
// { 7, 8, 9 }
// };
// int[,] b = new int[a.GetLongLength (1), a.GetLength (0)];
// for (int i = 0; i < a.GetLength(0); i++) {
// for (int j = 0; j < a.GetLength(1); j++) {
// b [j, i] = a [i, j];
// }
// }
// for (int i = 0; i < b.GetLength(0); i++) {
// for (int j = 0; j < b.GetLength(1); j++) {
// Console.WriteLine (b[i,j]);
// }
// }


// int[,] a = new int[,] {
// { 1, 2, 3, 0 },
// { 4, 5, 6, 11 },
// { 7, 8, 9, 10 }
// };
// int max = a[0,0];
// for (int i = 0; i < a.GetLength(0); i++) {
// for (int j = 0; j < a.GetLength(1); j++) {
// if (max < a[i,j]) {
// max = a [i, j];
// }
// }
// }
// Console.WriteLine (max);




int[,] a = new int[,] {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
int sum = 0;
for (int i = 0; i < a.GetLength(0); i++) {
sum += a [i, i];
}
Console.WriteLine (sum);








}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值