Вопрос задан 31.08.2020 в 09:18. Предмет Информатика. Спрашивает Пушенко Анастасия.

На языке С или С++ . Напишите программу, которая получает день и номер месяца и определяет дату

сле-дующего дня. Считайте, что год невисокосный (365 дней). Пример: Введите день и месяц: 25 12 Следующий день: 26 декабря Пример: Введите день и месяц: 28 2 Следующий день: 1 марта
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program in C to Determine the Next Date

Here's a program written in C that takes the day and month as input and determines the date of the next day. It assumes a non-leap year with 365 days.

```c #include

int main() { int day, month;

printf("Enter the day and month: "); scanf("%d %d", &day, &month);

// Determine the number of days in each month int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

// Check if the entered day and month are valid if (month < 1 || month > 12 || day < 1 || day > daysInMonth[month - 1]) { printf("Invalid date!\n"); return 0; }

// Check if it's the last day of the month if (day == daysInMonth[month - 1]) { // Check if it's the last day of the year if (month == 12) { day = 1; month = 1; } else { day = 1; month++; } } else { day++; }

// Print the next date printf("Next day: %d ", day);

// Determine the month name based on the month number char* monthNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; printf("%s\n", monthNames[month - 1]);

return 0; } ```

This program prompts the user to enter the day and month. It then checks if the entered date is valid. If it is, it determines the next date by incrementing the day. If the day is the last day of the month, it checks if it's the last day of the year. If it is, it sets the day to 1 and increments the month. Finally, it prints the next date in the format "Next day: [day] [month name]".

Example: ``` Enter the day and month: 25 12 Next day: 26 December ```

``` Enter the day and month: 28 2 Next day: 1 March ```

Please note that this program assumes the input is valid and does not handle leap years.

0 0

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

Последние заданные вопросы в категории Информатика

Задать вопрос