c#认证试题

 

namespace Test_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int result = 0;
            Console.WriteLine("请输入一个正整数:");
            int n = int.Parse(Console.ReadLine());
            if (n % 2 == 0)
            {
                for (int i = 0; i <= n ; i = i+2)
                    result = result + i;
                Console.WriteLine("{0}以内的偶数和为:{1}", n, result);
            }
            else
            {
                for (int i = 1; i <= n; i = i + 2)
                {
                    result = result + i;
                    Console.WriteLine("{0}以内的奇数和为:{1}", n, result);
                }
            }
       
        }
    }

 

}

 

 

Test—11

由于题中有关于异或运算,所以我们简单的来了解一下

异或运算符是指: 参与运算的两个值,如果两个相应位相同,则结果为0,否则为1。即:0^0=0, 1^0=1, 0^1=1, 1^1=0

例如:10100001^00010001=10110000

0^0=0,0^1=1    可理解为: 0异或任何数,其结果=任何数

1^0=1,1^1=0    可理解为: 1异或任何数,其结果=任何数取反 任何数异或自己,等于把自己置0

namespace Test_11

{     class Program    

{         static void Main(string[] args)        

{             Console.WriteLine("请输入原字符串:");            

string s_text = Console.ReadLine();            

Console.WriteLine("请输入密钥字符串:");            

string s_key = Console.ReadLine();          

   if (s_key.Length != s_text.Length)               

  Console.WriteLine("密钥长度必须与元字符串长度相等");            

else            

{   char ch;                

string s_result = null;               

  for (int i = 0; i <s_text.Length; i++)               

  {                     ch = s_text[i];                    

s_result+=(char)(ch ^ s_key[i]);                 }             

    Console.WriteLine("加密后的字符串为:");               

  for (int i = 0; i <s_result[i]; i++)                   

  Console.WriteLine(s_result[i]);

            }            

        }    

}

}

 

 

转载于:https://www.cnblogs.com/123yx/p/7537893.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值