Write a C# Sharp program to find whether a given year is a leap year or not

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to find whether a given year is a leap year or not

Sample Output:

Check whether a given year is leap year or not:                                                               
----------------------------------------------                                                                                                         
Input an year : 2017                                                                                          
2017 is not a leap year.

الأجوبة

using System;  
public class Exercise4  
{  
    public static void Main() 
{
    int chk_year;
    Console.Write("\n\n");
    Console.Write("Check whether a given year is leap year or not:\n");
    Console.Write("----------------------------------------------");
    Console.Write("\n\n");
    Console.Write("Input an year : ");
    chk_year= Convert.ToInt32(Console.ReadLine());
 
    if ((chk_year % 400) == 0)
 Console.WriteLine("{0} is a leap year.\n", chk_year);
    else if ((chk_year % 100) == 0)
 Console.WriteLine("{0} is not a leap year.\n", chk_year);
    else if ((chk_year % 4) == 0)
 Console.WriteLine("{0} is a leap year.\n", chk_year);
    else
 Console.WriteLine("{0} is not a leap year.\n", chk_year);
}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...