C# Code to Check the given number is Positive(+ve) or
negative(-ve)
A simple if condition makes it possible.Checking the given number is +ve or -ve is have only 3 to 6 lines of simple code. It is very easy to understand.Firstly create a new project or a website.the new form must have at least a Text box (for inputting the value),a submit button(to check the number -ve or not by clicking the button) finally another Text box or a label for output the result.My final form looks like this.
![]() |
| Design for the program |
This form have One Text box for inputting the checking value named as "txtNumber",a submit button to execute the code for checking the number is positive or negative named as btnCheck and the output will be printed in alabel named as lblResult the labels forecolor set as red
after creating the form just double click the button and write this code:
private void btnCheck_Click(object sender, EventArgs e)
{
int inputNumber; //inyeger variable for storing the inputted value
inputNumber = Convert.ToInt32 (txtNumber.Text ); //assign the inputted value to the
// variable'inputNumber'
if (inputNumber >= 0) // if the given number is greater than zero then the number is
// positive
{
lblResult.Text = "The Nunber is Positive"; //print output in labelbox 'lblResult'
}
else //else the number is negative
{
lblResult.Text = "The Number is Negative"; //print output in labelbox 'lblResult'
}
}
See also:
Code for Find FACTORIAL of a Given Number From TextBox
Code for Find SUM of N Natural Numbers
Code For Find SUM and AVERAGE
See also:
Code for Find FACTORIAL of a Given Number From TextBox
Code for Find SUM of N Natural Numbers
Code For Find SUM and AVERAGE

ReplyDeleteLife is a battle, if you don't know how to defend yourself then you'll end up being a loser. So, better take any challenges as your stepping stone to become a better person. Have fun, explore and make a lot of memories.
n8fan.net
www.n8fan.net
I’m impressed, I need to say. Actually hardly ever do I encounter a blog that’s both educative and entertaining, and let me let you know, you may have hit the nail on the head. Your idea is excellent; the issue is something that not enough individuals are talking intelligently about. I'm very blissful that I stumbled across this in my search for something referring to this. real money casino
ReplyDelete