Answer to Question #284397 in C# for OraaKim

Question #284397

Create a program that accept six (6) numbers and check whether each number is either odd or even number. Hence, if the sum of odd numbers is greater than the sum of

even numbers, calculate the sum (all odd numbers), otherwise, calculate the sum (all even numbers).


Thanks for answering this I really appreciate it!


1
Expert's answer
2022-01-05T01:40:05-0500
using System;

namespace Negative_6_numbers
{
    internal class Program
    {
        public static void Main(string[] args)
        {
           /*
Create a program that accept six (6) numbers and check whether each number is either odd or
 even number. Hence, if the sum of odd numbers is greater than the sum of
even numbers, calculate the sum (all odd numbers), otherwise,
 calculate the sum (all even numbers).
*/

            int[] array = new int[6];
            int evens = 0;
            int odds = 0;
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write($"Enter a {i + 1} number: ");
                array[i] = int.Parse(Console.ReadLine());
                if (array[i] % 2 == 0) {
                    Console.WriteLine("Even:");
                    evens += array[i];
                }
                else{
                    Console.WriteLine("Odd");
                    odds += array[i];
                }
            }
            if(evens > odds)
                Console.WriteLine($"Sum of even numbers: {evens}");
            else if(odds > evens)
                Console.WriteLine($"Sum of odd numbers: {odds}");
            else
                Console.WriteLine("The sum of even and odd numbers is equal:");
            Console.ReadLine();
        }
    }
}

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