zoukankan      html  css  js  c++  java
  • 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]);

                }            

            }    

    }

    }

     

  • 相关阅读:
    计算机网络知识 第一部分
    LAMP环境安装
    Axure RP 交互设计
    Axure RP 界面功能
    Axure RP 界面功能介绍
    Axure RP 第一部分
    Grub管理修改root口令
    MYSQL 部分练习题
    工作日志示例
    计算机网络的分类
  • 原文地址:https://www.cnblogs.com/123yx/p/7537893.html
Copyright © 2011-2022 走看看