C# Program to Calculate Sum of first N natural numbers

In this C# program, we will take input from the user and generate the sum of first N natural Numbers. The sum of natural numbers up to 10 is: 1+2+3+4+5+6+7+8+9+10=55

 

C# Program to Calculate Sum of first N natural numbers Code:

private static void Main(string[] args)
        {
            int i, sum = 0, n;
            Console.Write("Enter the Nth Number : ");
            n = int.Parse(Console.ReadLine());
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine("Sum of N Numbers : " + sum);
            Console.ReadLine();
        }

C# Program to Calculate Sum of first N natural numbers Output:

C#-Program-to-Calculate-Sum-of-first-N-natural-numbers

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
1 + 5 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2022 CodingFusion
75 Important SQL Server queries you should know