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

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:

2010

output

3
с++​

Показать ответ
Ответ:
redf0x0
redf0x0
09.10.2020 14:43

#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

0,0(0 оценок)
Популярные вопросы: Информатика
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота