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

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

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