[C#]判断回文串;数组中最大最小值,平均值
判断回文:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 判断回文 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int len=s.Length; int Flag=0; for (int i = 0; i < (len-1)/2; i++) { if(s[i]!=s[len-1-i]) { Flag=1; break; } } if(Flag==1) Console.WriteLine("no"); else Console.WriteLine("yes"); } } }
数组中最大最小值,平均值:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int max=num[0]; int min = num[0]; float sum=num[0]; for(int i=1;i<num.Length;i++) { if(max<num[i]) max=num[i]; if(min>num[i]) min=num[i]; sum+=num[i]; } float average = sum / num.Length; Console.WriteLine("最大值为{0}", max); Console.WriteLine("最小值为{0}", min); Console.WriteLine("平均值为{0}", average); } } }