﻿ C# Sharp exercises: Display the value of an integer n is 1,0 and -1 for the value of an integer m - w3resource

# C# Sharp exercises: Display the value of an integer n is 1,0 and -1 for the value of an integer m

## C# Sharp Conditional Statement: Exercise-6 with Solution

Write a C# Sharp program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.

Sample Solution:-

C# Sharp Code:

``````using System;
public class Exercise6
{
public static void Main()
{
int m,n;
Console.Write("\n\n");
Console.Write("Display the value of n is 1,0 and -1 for the value of er m:\n");
Console.Write("----------------------------------------------------------");
Console.Write("\n\n");

Console.Write("Input the  value of m :");
if(m!=0)
if(m>0)
n=1;
else
n=-1;
else
n=0;
Console.Write("The value of m = {0} \n",m);
Console.Write("The value of n = {0} \n\n",n);
}
}
```
```

Sample Output:

```Display the value of n is 1,0 and -1 for the value of er m:
----------------------------------------------------------
Input the  value of m :5
The value of m = 5
The value of n = 1
```

Flowchart :

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

﻿

New Content: Composer: Dependency manager for PHP, R Programming