I need help with my solution...
I have to make windows form app, that has two textbox'es, one button, and richtexbox.
And it has to calculate even numbers from the texbox interval.
Ex.. texbox1 (int 1), texbox2 (int 5), but int1 is less than int5 ( x
Maby you have some opinions how to make it work with FOR cycle?
X = 1; Y = 5;
=========================
| Number | Factorial |
=========================
| 2 | 2 |
| 4 | 24 |
=========================
I have written program in CMD c#, but I want some more experience, so maby you could help me with this...Waiting for some SOS response.
Vikram AgrawalPosted Nov 10, 2014, 8:51 AM
Hi dear,
here Is the logic code for your problem which is written in C#
private double GetFactorial(int number)
{
if(number<=0)
return 1;
if(number<=2)
return number;
double fact=1;
for(int i=number;i>0;i--)
{
fact=fact*i;
}
return fact;
}
private bool IsEven(int number)
{
if(number%2==0)
return true;
else
return false;
}
private void Button1_Click(object sender,EventArgs e)
{
int num1=Convert.ToInt32(txtNum1.Text);
int num2=Convert.ToInt32(txtNum2.Text);
string result="";
if(num1
for(int i=num1;i<=num2;i++)
{
if(IsEven(i))
{
result + = i.ToString() + " - " + GetFactorial(i).ToString() + "\n";
}
}
}
else
{
for(int i=num2;i<=num1;i++)
{
if(IsEven(i))
{
result + = i.ToString() + " - " + GetFactorial(i).ToString() + "\n";
}
}
}
rtbResult.Text=result;
}
Here I created two user define methods
1- for get factorial of any number ie GetFactorial(int)
2- for checking number is even or not ie IsEven(int)
Thank You,
please mark This is Correct answer if it is helpful to you
itbox paslaugosPosted Nov 10, 2014, 8:07 AM