Submission
Status:
----------
Score: 0
User: Pera
Problemset: เลขดวง
Language: c
Time: 0.001 second
Submitted On: 2024-10-16 20:00:18
#include <stdio.h>
int main() {
int days_in_month, first_day, birthday;
int sum = 0;
// Input
printf("Enter the number of days in the month: ");
scanf("%d", &days_in_month);
printf("Enter the day of the week for the first day (1-Sun, 7-Sat): ");
scanf("%d", &first_day);
printf("Enter the birthday: ");
scanf("%d", &birthday);
// Calculate the day of the week for the birthday
int birthday_day_of_week = ((birthday - 1 + (first_day - 1)) % 7) + 1;
// Check and sum the surrounding days
if (birthday - 7 > 0) sum += birthday - 7; // Up
if (birthday + 7 <= days_in_month) sum += birthday + 7; // Down
if (birthday_day_of_week > 1) sum += birthday - 1; // Left
if (birthday_day_of_week < 7 && birthday < days_in_month) sum += birthday + 1; // Right
// Output
printf("The sum of the surrounding days is: %d\n", sum);
return 0;
}