Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check two given integers and return true if one is negative and one is positive

C# Sharp Basic: Exercise-18 with Solution

Write a C# program to check two given integers and return true if one is negative and one is positive.

C# Sharp Exercises: Check two given integers and return true if one is negative and one is positive

Sample Solution:

C# Sharp Code:

using System;
using System.Collections.Generic;

public class Exercise18 {
  static void Main(string[] args)
        {
           Console.WriteLine("\nInput first integer:");  
           int x = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine("Input second integer:");  
           int y = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine("Check if one is negative and one is positive:");
           Console.WriteLine((x < 0 && y > 0) || (x > 0 && y < 0));
        }
}

Sample Output:

Input first integer:                                                   
-5                                                                     
Input second integer:                                                  
25                                                                     
Check if one is negative and one is positive:                          
True 

Flowchart:

Flowchart: C# Sharp Exercises - Check two given integers and return true if one is negative and one is positive

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to create a new string from a given string (length 1 or more ) with the first character added at the front and back.
Next: Write a C# program to compute the sum of two given integers, if two values are equal then return the triple of their sum.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.