Do you want to print natural number series and also want to print the sum . Actually it is formula based but if you want to print series also then you have to go with for loop. the program is given below.
If you feel any difficulty while running or understanding the below program, then feel free to comment.
using System;
namespace ConsoleHub
{
class Programs
{
static void Main(string[] args)
{
string strSeries = "0";
int sum = 0;
for (int i = 0; i <= 10; i++)
{
if (i.ToString() != "0")
{
strSeries = strSeries + "+" + i;
}
sum = sum + i;
}
Console.WriteLine("{0}={1}", strSeries, sum);
Console.ReadLine();
}
}
}
No comments:
Post a Comment