To sum of natural number in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace value
{
class Program
{
static void Main(string[] args)
{
int n,m=0,i;
Console.WriteLine("Enter the number.");
n = int.Parse(Console.ReadLine());
for(i=1; i<=n;i++)
{
m += i;
}
Console.WriteLine("sum of natural number is {0}",m);
Console.ReadLine();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace value
{
class Program
{
static void Main(string[] args)
{
int n,m=0,i;
Console.WriteLine("Enter the number.");
n = int.Parse(Console.ReadLine());
for(i=1; i<=n;i++)
{
m += i;
}
Console.WriteLine("sum of natural number is {0}",m);
Console.ReadLine();
}
}
}
output :-