1.1
using System;
using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Test1_1
{ class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int oddn=0; int evenn=0; if (n % 2 != 0) { for (int i = 1; i <= n; i++) { if (i % 2 != 0) { oddn = oddn + i; } } Console.WriteLine("奇数和为:{0}", oddn); } else { for (int j = 1; j <= n; j++) { if (j % 2 == 0) { evenn = evenn + j; } } Console.WriteLine("偶数和为:{0}", evenn); } Console.Read(); } }}1.11
using System;
using System.Collections.Generic;using System.IO;using System.Linq;using System.Security.Cryptography;using System.Text;using System.Threading.Tasks;namespace Test1_11
{ class Program { static void Main(string[] args) { //string s_text, s_key, s_result = null; //char ch; //Console.WriteLine("请输入原字符串:"); //s_text = Console.ReadLine(); //int m = s_text.Length; //原文字符串长度 //Console.WriteLine(s_text); //Console.WriteLine("请输入密钥字符串:"); //s_key = Console.ReadLine(); //int n = s_key.Length; //密钥字符串长度 //if(m!=n) //{ // Console.WriteLine("密钥字符串与原文字符串长度必须相等"); //} //else //{ // for(int i=0;i<m;i++) // { // } 这种加密方式不会 TripleDESCryptoServiceProvider tDCtSP = new TripleDESCryptoServiceProvider(); MemoryStream ms = new MemoryStream(); ICryptoTransform crypt = tDCtSP.CreateEncryptor(); Console.WriteLine("请输入原字符串:"); string data = Console.ReadLine(); UTF8Encoding utf = new UTF8Encoding(); byte[] databyte = utf.GetBytes(data); CryptoStream cts = new CryptoStream(ms, crypt, CryptoStreamMode.Write); cts.Write(databyte, 0, databyte.Length); cts.Close(); byte[] msdata = ms.ToArray(); Console.WriteLine(utf.GetString(msdata)); Console.Read(); } }}