task1.cs 855 B

1234567891011121314151617181920212223242526272829303132
  1. //1
  2. Console.WriteLine("Введите год рождения: ");
  3. int year1 = int.Parse(Console.ReadLine());
  4. for (int year = 1900; year < 2000; year++)
  5. {
  6. for (int month = 1; month <= 12; month++)
  7. {
  8. for (int day = 1; day <= DateTime.DaysInMonth(year, month); day++)
  9. {
  10. DateTime date = new DateTime(year, month, day);
  11. int age = year1 - year;
  12. int sum1 = CalculateSumOfSquares(year) - (day * day);
  13. if (sum1 == age)
  14. {
  15. Console.WriteLine("Дата рождения по свойству Васи: " + date.ToShortDateString());
  16. }
  17. }
  18. }
  19. }
  20. static int CalculateSumOfSquares(int year)
  21. {
  22. int sum = 0;
  23. foreach (char c in year.ToString())
  24. {
  25. sum += int.Parse(c.ToString()) * int.Parse(c.ToString());
  26. }
  27. return sum;
  28. }