Exercise 2: Add all values between 1000 and 2000, that are divisible by 7.
static void Main(string[] args)
{
int N = 1000;
int sum = 0;
do
{
if (N % 7 == 0)
{
sum += N;
Console.WriteLine("Number: {0} Sum: {1}", N, sum);
}
N++; //get next value
} while (N <= 2000);
Console.ReadLine();
}
No comments:
Post a Comment