Answer to Question #187132 in C# for angelo r reyes

Question #187132

Write a function-oriented program that calculates the sum of the sequence number from 1 to n. Thus, if the input is 5, the output should be 15 because: 1 + 2 + 3 + 4 + 5 = 15


1
Expert's answer
2021-05-03T07:54:15-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


        static void Main(string[] args)
        {
            
            int N;
            Console.Write("Enter N: ");
            N = int.Parse(Console.ReadLine());
            int sum=0;
            for (int i = 1; i <= N; i++)
            {
                sum += i;
            }


            Console.WriteLine("The sum of the sequence number from 1 to {0} = {1}",N,sum);
            Console.ReadLine();


        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS