We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Tuesday, January 12, 2016

Write a program sum of the all numbers from 0 to which is given specific the number in C#

class SumNumber
    {
        static void Main()
        {
            int n = 0;
            Console.WriteLine("Enter the number");
            Console.Write("The Num = ");
            n = int.Parse(Console.ReadLine());
            int num = 1;
            int sum = 1;
            Console.Write("The sume is :  1");
            while (num < n)
            {
                num++;
                sum += num;
                Console.Write("+" + num);
            }
            Console.WriteLine(" = " + sum);
            Console.ReadLine();
        }

    }

Output:

No comments: