Sum Of series in c#.net source code with output and explanation
in this program we will see how to calculate sum of series till sum number like 10 , 20 , etc....
Now what we will do we will just take two value assign them as 0 and 1. so , at least we will get
some value at start.
In this article i have shown here how to calculate sum of series in c# .net on Page Init
event.
protected void Page_Init(object sender, EventArgs e)
{
int a=0; //here i have initialize two valus as 0 and 1.
int b=1;
int num=20;
Response.Write("Sum Of series Before:"+num);
Response.Write("</br>");
int sum=0;
for (int j=1;j<=num;j++)
{
sum=a+b; //swappping.............
a=b;
b=sum;
Response.Write(sum+"-"); // printing the values.......
}
}
OUTPUT
Sum Of series Before:20
1-2-3-5-8-13-21-34-55-89-144-233-377-610-987-1597-2584-4181-6765-10946
IF YOU WILL TAKE NUM=10
THEN OUTPUT WILL
Sum Of series Before:10
1-2-3-5-8-13-21-34-55-89
0 comments: