using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int sum = Test(, , , , );
Console.WriteLine("多个整数之和为:{0}", sum);
Console.ReadKey();
} static int Test(params int[] arr)
{
int sum = ;
for (int i = ; i < arr.Length; i++)
{
sum += arr[i];
}
return sum;
}
}
}

改进后:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{ Console.WriteLine("请输入需要相加的整数个数");
int i = Convert.ToInt32(Console.ReadLine());
int[] readint = new int[i];
for (int k = ; k < i; k++)
{
Console.WriteLine("请输入需要相加的整数");
readint[k] = Convert.ToInt32(Console.ReadLine());
}
int sum = Test(readint);
Console.WriteLine("多个整数之和为:{0}", sum);
Console.ReadKey();
} static int Test(params int[] arr)
{
int sum = ;
for (int i = ; i < arr.Length; i++)
{
sum += arr[i];
}
return sum;
}
}
}

最新文章

  1. 手把手教从零开始在GitHub上使用Hexo搭建博客教程(三)-使用Travis自动部署Hexo(1)
  2. AAS代码第2章
  3. javascript 红宝书笔记之函数、变量、参数、作用域
  4. 让那些为Webkit优化的网站也能适配IE10(转载)
  5. 学的一点点ps
  6. javap(反汇编命令)详解【转】
  7. xshell无法连接centos 6.6的问题
  8. jQuery easyui 提示框
  9. Swift学习笔记三
  10. 《how to design programs》第11章自然数
  11. android笔试题
  12. 【转】Android 网络通信框架Volley简介(Google IO 2013)
  13. 处理win7任务栏通知区域图标异常问题
  14. Nuget发布教程
  15. [Swift]LeetCode895. 最大频率栈 | Maximum Frequency Stack
  16. mysql创建用户与pymsql模块
  17. halcon 特征测量
  18. 从session中获取当前用户的工具类
  19. android 数据库更新
  20. Vue + Spring Boot从零开始搭建个人网站(一) 之 项目前端Vue.js环境搭建

热门文章

  1. Lowest Common Ancestor of a Binary Tree, with Parent Pointer
  2. 最大流之sap算法
  3. Core 发布至Linux
  4. 读书笔记:js设计模式
  5. MapList 自己封装的
  6. 文本相似度算法——空间向量模型的余弦算法和TF-IDF
  7. float存储方式编程验证
  8. Git基础 1 ---- 版本控制系统的介绍
  9. 【转】Nginx+Tomcat搭建高性能负载均衡集群
  10. 五毛的cocos2d-x学习笔记01-创建项目