编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/04/30 05:40:06
编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成
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;
}
{
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;
}
1编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成本题.
c语言编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成本题.
编程求1到n中能被3或7整除的数之和.分别用for循环语句和while循环语句完成
1.分别用while for do- while循环语句编程求从1加到1000的和.
分别用while循环和for循环语句编写程序计算1到100的和
2、分别用三种循环语句(while语句、do-while语句、for语句),实现求1~100的累加和
c语言编程:分别用for循环和while循环,找出1000到2000间所有素数(只能被 1和自身整除的数)
用for循环语句编程,写出,0到100之间能被3整除的个数
用MATLAB编程,编制一个M文件,分别使用for循环和while循环语句计算1^1+2^2+3^3+4^4+5^5+.
求1-100的累加和分别用while,do...while和for这两种循环语句实现
mathematica 分别用Do 语句、For语句、While语句三种循环控制语句完成1到100所有自然数求和运算.
输出1--100间不能被3 整除的数,用do-while结构循环语句