w3resource
C# Sharp Programming Exercises

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 :");
    m= Convert.ToInt32(Console.ReadLine());
   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 :

Flowchart: Display the value of an integer n is 1,0 and -1 for the value of an integer m

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to read age of a candidate and determine whether it is eligible for casting his/her own vote.
Next: Write a C# Sharp program to accept the height of a person in centimeter and categorize the person according to their height.

What is the difficulty level of this exercise?



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