Write a C# Sharp program to check whether a given number (integer) is Oddish or Evenish
- برمجة سي شارب
- برمجة
- 2021-05-31
- ahmadghneem
الأجوبة
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");
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال