When we multiply different numbers they come with different sign such as (Plus (+), Negative (-)) suppose : (-2) * (+2) = -4, your task is to write such an application that show(Display) the sign of four real number after multiplication by using sequence of if operator.[Note you can’t calculate it] Hint : logical operator
using System;
namespace program
{
class Program
{
public static void Main(string[] args)
{
int n;
Console.Write("Write n: ");
n = Convert.ToInt32(Console.ReadLine());
int[] mas = new int[n];
for(int i= 0; i < n; i++)
{
Console.Write("Write the number " + (i+1) + ": ");
mas[i] = Convert.ToInt32(Console.ReadLine());
}
int countNegative = 0;
bool isNull = false;
for(int i = 0; i < n; i++)
{
if(mas[i] == 0)
{
isNull = true;
break;
}
if(mas[i] < 0)
countNegative++;
}
if(isNull)
Console.WriteLine("Multiplication is 0");
else if(countNegative % 2 == 0)
Console.WriteLine("Multiplication is positive");
else
Console.WriteLine("Multiplication is negative");
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment