Answer to Question #181115 in C# for Kashif Rehman

Question #181115

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


1
Expert's answer
2021-04-14T05:15:38-0400
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);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS