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:

Post a Comment

Thank you for reading of my article