Ad

Tuesday, July 2, 2013

Program To Find a Sum of N Natural Numbers

OverView:

In this article i would like to publish Program To Find a Sum of N Natural Numbers.


Description:

                   Here Sum of N Natural Numbers.For caluclating that we have a formulae for it.

                                n*(n+1)/2

--> Code:

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

namespace sumofnnaturalnumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Example To Find Sum of N Natural Numbers");
            int n;
            long n1;
            Console.WriteLine("Enter N Value");
            n = Convert.ToInt32(Console.ReadLine());
            n1=n*(n+1)/2;
            Console.WriteLine("Sum of {0} is {1}",n,n1);
            Console.ReadLine();
        }
    }
}

OutPut:

No comments: