Sponsored Ad

Friday, April 27, 2012

Natural Number (0 to 10) Series and Series Sum in C#

Do you want to print natural number series and also want to print the sum . Actually it is formula based but if you want to print series also then you have to go with for loop. the program is given below.

If you feel any difficulty while running or understanding the below program, then feel free to comment.

Natural Number (0 to 10) Series and Series Sum in C#

using System;

namespace ConsoleHub
{
    class Programs
    {
        static void Main(string[] args)
        {
            string strSeries = "0";
            int sum = 0;
            for (int i = 0; i <= 10; i++)
            {
                if (i.ToString() != "0")
                {
                    strSeries = strSeries + "+" + i;
                }
                sum = sum + i;

            }
            Console.WriteLine("{0}={1}", strSeries, sum);

            Console.ReadLine();
        }
    }
}

Sponsored Ad

Development Updates