C implements the method of calculating zodiac signs by year

  • 2021-01-03 21:01:25
  • OfStack

This article gives an example of how C# implements the method of calculating zodiac signs by year. Share to everybody for everybody reference. The specific analysis is as follows:

The code is relatively simple, because 2008 is the year of the Rat, so the program starts with 2008 as the standard, 2008 also has special significance for Chinese people


private static void shuxiang(int year)
{
  string[] shuxiang = {" The rat "," The cow "," The tiger "," The rabbit "," dragon "," The snake "," The horse "," The sheep "," The monkey "," chicken "," The dog "," The pig "};
  int tmp = year - 2008;
  if (year < 2008)
  {
 Console.WriteLine(shuxiang[tmp % 12 + 12]);
  }
  else
  {
 Console.WriteLine(shuxiang[tmp % 12]);
  }
}

Hopefully this article has helped you with your C# programming.


Related articles: