i
, kiểm tra giá trị của biểu thức chia lấy dư cho 2 i % 2
, nếu:
i % 2 == 0
: là số chẵn.i % 2 != 0
: là số lẻ./* C# Program to Check whether the Entered Number is Even or Odd This is a C# Program to check whether the entered number is even or odd. Problem Description This C# Program checks if a given integer is Odd or Even. Problem Solution Here if a given number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lession1 { class Program { static void Main(string[] args) { int i; Console.Write("Enter a Number : "); i = int.Parse(Console.ReadLine()); if (i % 2 == 0) { Console.Write("Entered Number is an Even Number"); Console.Read(); } else { Console.Write("Entered Number is an Odd Number"); Console.Read(); } } } }[/su_spoiler]
Thực hiện các bước tuần tự theo nội dung Bài học nhé!
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!