This program will help you, try it out
using System;
class SumOfOdds
{
public static void Main()
{
int x=0, sumodd=0, sumeven=0, sumdiv7 = 0 ,totalno7 = 0, i;
for (i=0 ; i<=20 ; i++)
{
x = i % 2;
if (x != 0)
{
sumodd = sumodd + i;
}
if (x == 0)
{
sumeven = sumeven + i;
}
}
//checking for the sum & no. of numbers divisible by 7
x = 0; // resetting the value of ''x''
for (i=100; i<=200;i++)
{
x = i % 7;
if (x == 0)
{
sumdiv7 = sumdiv7 + i;
totalno7 = totalno7 + 1;
}
}
Console.WriteLine("Sum of all odd numbers from 1 - 20 = " + sumodd + "\n");
Console.WriteLine("Sum of all even numbers from 1 - 20 = " + sumeven + "\n");
Console.WriteLine("Sum of all numbers from 100 - 200, divisible by 7 = " +
sumdiv7 + "\n");
Console.WriteLine("Total numbers from 100 - 200, divisible by 7 = " + totalno7 + "\n");
Console.ReadLine();
}
}