程序如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _032_练习6
{
class Program
{
static void Main(string[] args)
{
for(int fre = 1; fre <= 1000; fre++)
{
int group = 1;
int n = 1;
int sum = 0;
if (fre % 7 == 0)
{
group++;
Console.WriteLine("能被7整除的数有" + fre);
sum += fre;
}
if (group % 5 == 0)
{
n++;
Console.WriteLine("第"+ n +"组被7整除的数之和为"+ sum);
}
}
Console.ReadKey();
}
}
}
修改了一下
for(int fre = 1; fre <= 1000; fre++)
{
int group = 0;
int n = 1;
int sum = 0;
if (fre % 7 == 0)
{
group++;
Console.WriteLine("能被7整除的数有" + fre);
sum += fre;
}
if (group > 0 && group % 5 == 0)
{
Console.WriteLine("第"+ n +"组被7整除的数之和为"+ sum);
n++;
sum = 0;
}
}
Console.ReadKey();
还是不对