
Teacher’s day is celebrated each year on the first Sunday of the October. Given natural number n,
that represents the number of the year. Output the date of the Teacher’s day of that year. Example:Input:2010Output3с++

Ответы на вопрос

Ответ:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int y;
char buffer[80];
cout << "Year = ";
cin >> y;
tm time_in;
time_in.tm_sec = 0; // second
time_in.tm_min = 0; // minute
time_in.tm_hour = 0; // hour
time_in.tm_mday = 1; // 1-based day
time_in.tm_mon = 9; // 0-based month
time_in.tm_year = y - 1900; // year since 1900
time_t time_temp = mktime (&time_in); // Convert the local time to a calendar value.
tm* time_out = localtime (&time_temp); // Converts a time_t time value to a tm structure
if (time_out->tm_wday > 0) // if it is not Sunday, go to the next Sunday
time_out->tm_mday += 7 - time_out->tm_wday;
strftime(buffer, 80, "%d.%m.%Y", time_out); // date formatting for output
cout << "\nTeachers day is " << buffer << "\n";
}
Объяснение: explanations in the comments to the program



To determine the date of Teacher's Day for a given year, we need to find the first Sunday of October for that year. Here's how you can calculate it in C++:
```cpp
#include
int main() { int year; std::cout << "Enter the year: "; std::cin >> year;
// Create a date object for October 1st of the given year std::chrono::year_month_day date{std::chrono::year{year}, std::chrono::month{10}, std::chrono::day{1}};
// Find the weekday of October 1st std::chrono::weekday weekday{date};
// Calculate the number of days to the first Sunday int days_to_sunday = (std::chrono::Sunday - weekday).count();
// Add the number of days to October 1st to get the date of the first Sunday of October std::chrono::year_month_day teacher_day_date = date + std::chrono::days{days_to_sunday};
// Output the date of Teacher's Day std::cout << "Teacher's Day in " << year << " is on " << teacher_day_date << std::endl;
return 0; } ```
This program uses the `
Please note that the program assumes the first Sunday of October as the date for Teacher's Day. This may vary depending on the country or region.


Топ вопросов за вчера в категории Информатика








Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili