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

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
с++​

Ответ:
Rifik
Rifik
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
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?