c#编程题:求1000以内既能被5整除又能被7整除的数,并每五个输出一次和

如题所述

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace question
{
class Program
{
static void Main(string[] args)
{
ArrayList Value = new ArrayList();
int x=0;
for (int i = 0; i <= 1000; i++)
{
if (i % 5 == 0&&i%7==0)
{
Value.Add(i);

}
}

foreach (int j in Value)
{
Console.Write(j+" ");
x++;
if(x%5==0)
{
int sum=0;
for(int y=x;y>=x-5;y--)
{
sum=sum+(int)Value[y];
}
Console.WriteLine("和是" + sum);

}
}
Console.ReadLine();
}
}
}
我这是从0开始算的 应该符合你的要求
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-01-06
int a = 0;
int b = 0;
int c = 0;
int j = 0;
int d = 0;
for (int i = 0; i < 1000; i++)
{
a = i % 5;
b = i % 7;
if (a == 0 && b == 0)
{
j++;
c = j % 5;
d += i;
Response.Write(i+"<br/>");
if (c == 0)
{
Response.Write("和为:"+d+"<br>");
d = 0;
}
}
}
第2个回答  2011-01-06
int i=1000;
int s=0;
int n=1;
while(i--){
if(!(i%5&&i%7))
{
s+=i;
n++;
}
if(n==5){n=1;
cw(s);s=0;
}
}本回答被网友采纳
相似回答