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
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();
}
}
}
Comments
Leave a comment