编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成

问题描述:

编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成
1个回答 分类:综合 2014-10-25

问题解答:

我来补答
int sum(int n)
{
    List<int> list = new List<int>();
    for(int x = 0; x <= n; x++)
    {
        if(x % 3 == 0  || x % 7 == 0)
        {
            list.Add(x);
        }
    }
    int x = 0;
    int result = 0;
    while(x < list.Count)
    {
        result += list[x++];
    }
    return result;
}
 
 
展开全文阅读
剩余:2000