Factorial Number program source code | From 1 to n range | c#.net
In this program i have shown how to find factorial number of given range.
using for loop i have calculated factorial number from 1 to 5 .
But , we can calculate factorial number from 1 to n using below given source code.
output is there.
same logic we can apply in c language , vb.net also but difference is only of syntax will be changed.
rest logic will be same.
protected void Page_Init(object sender, EventArgs e)
{
int sum = 1;
int i = 5;
for (int j = i; j > 0; )
{
for (int k = 1; k <= j; )
{
sum = sum * j;
j--;
}
Response.Write("Factorial of " + i + "is" + "\t" + sum);
Response.Write("</br>");
i--;
j = i;
sum = 1;
}
}
Factorial of 5 is 120
Factorial of 4 is 24
Factorial of 3 is 6
Factorial of 2 is 2
Factorial of 1 is 1
In this program i have shown how to find factorial number of given range.
using for loop i have calculated factorial number from 1 to 5 .
But , we can calculate factorial number from 1 to n using below given source code.
output is there.
same logic we can apply in c language , vb.net also but difference is only of syntax will be changed.
rest logic will be same.
protected void Page_Init(object sender, EventArgs e)
{
int sum = 1;
int i = 5;
for (int j = i; j > 0; )
{
for (int k = 1; k <= j; )
{
sum = sum * j;
j--;
}
Response.Write("Factorial of " + i + "is" + "\t" + sum);
Response.Write("</br>");
i--;
j = i;
sum = 1;
}
}
Factorial of 5 is 120
Factorial of 4 is 24
Factorial of 3 is 6
Factorial of 2 is 2
Factorial of 1 is 1
0 comments: