美文网首页c#学习
c#的一道计算多组 A B的题目

c#的一道计算多组 A B的题目

作者: 李药师_hablee | 来源:发表于2019-09-27 21:28 被阅读0次
    using System;
    
    /*计算N个A+B的值
     * sampleInput:3
     * 1 2
     * 3 2
     * 4 5
     * sampleOutput
     * 3
     * 5
     * 9
     */
    //属于计数型循环
    
    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
                int N, A, B;
                N = Convert.ToInt32(Console.ReadLine());
                for(int i=0;i<N;i++)
                {
                    string s = Console.ReadLine();//将A B以字符串读入
                    string[] st = s.Split(' ');//分成字符数组
                    //进行强制转换
                    A = Convert.ToInt32(st[0]);
                    B = Convert.ToInt32(st[1]);
    
                    //打印A+B
                    Console.WriteLine("{0}", A + B);
                }
            }
        }
    }
    
    

    结果

    捕获1.PNG

    相关文章

      网友评论

        本文标题:c#的一道计算多组 A B的题目

        本文链接:https://www.haomeiwen.com/subject/twtgectx.html