Q:

Write a C# Sharp program to check whether a given number (integer) is Oddish or Evenish

0

Write a C# Sharp program to check whether a given number (integer) is Oddish or Evenish. 
A number is called "Oddish" if the sum of all of its digits is odd, and a number is called "Evenish" if the sum of all of its digits is even.
Example:
120 -> Oddish
321 -> Evenish
43 -> Oddish
4433 -> Evenish
373 -> Oddish.
Expected Output:
Original number: 120
Check the said number is Oddish or Evenish! Oddish
Original number: 321
Check the said number is Oddish or Evenish! Evenish
Original number: 43
Check the said number is Oddish or Evenish! Oddish
Original number: 4433
Check the said number is Oddish or Evenish! Evenish

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 120;
            Console.WriteLine("Original number: " + n);
            Console.WriteLine("Check the said number is Oddish or Evenish! " + test(n));
            n = 321;
            Console.WriteLine("\nOriginal number: " + n);
            Console.WriteLine("Check the said number is Oddish or Evenish! " + test(n));
            n = 43;
            Console.WriteLine("\nOriginal number: " + n);
            Console.WriteLine("Check the said number is Oddish or Evenish! " + test(n));
            n = 4433;
            Console.WriteLine("\nOriginal number: " + n);
            Console.WriteLine("Check the said number is Oddish or Evenish! " + test(n));
        }
        public static string test(int n)
        {
            string str = n.ToString();
            int total = 0;
            for (int i = 0; i < str.Length; i++)
                total += int.Parse(str[i].ToString());
            return (total % 2 == 0 ? "Evenish" : "Oddish");
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now