#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int main() {
int year;
cout << "Enter a year: ";
cin >> year;
// Set the tm struct to January 1 of the desired year
tm time_in = { 0, 0, 0, 1, 0, year - 1900 };
// Convert tm struct to time_t and back to tm
time_t time_temp = mktime(&time_in);
tm *time_out = localtime(&time_temp);
// Calculate the number of days in the year
int days_in_year = 365 + (time_out->tm_yday == 365 && time_out->tm_mon > 1);
// Set the width of the day name column
cout << setw(10);
// Print header row with the name of each day
cout << "Sun Mon Tue Wed Thu Fri Sat" << endl;
// Calculate the number of spaces to leave before the first day of the year
int spaces = time_out->tm_wday;
cout << setw(spaces * 3) << "";
// Loop through all days of the year
for (int day = 1; day <= days_in_year; ++day) {
cout << setw(2) << day << " ";
// Start a new line after every 7 days
if ((day + spaces) % 7 == 0) {
cout << endl;
}
}
return 0;
}
#include <iomanip>
#include <ctime>
using namespace std;
int main() {
int year;
cout << "Enter a year: ";
cin >> year;
// Set the tm struct to January 1 of the desired year
tm time_in = { 0, 0, 0, 1, 0, year - 1900 };
// Convert tm struct to time_t and back to tm
time_t time_temp = mktime(&time_in);
tm *time_out = localtime(&time_temp);
// Calculate the number of days in the year
int days_in_year = 365 + (time_out->tm_yday == 365 && time_out->tm_mon > 1);
// Set the width of the day name column
cout << setw(10);
// Print header row with the name of each day
cout << "Sun Mon Tue Wed Thu Fri Sat" << endl;
// Calculate the number of spaces to leave before the first day of the year
int spaces = time_out->tm_wday;
cout << setw(spaces * 3) << "";
// Loop through all days of the year
for (int day = 1; day <= days_in_year; ++day) {
cout << setw(2) << day << " ";
// Start a new line after every 7 days
if ((day + spaces) % 7 == 0) {
cout << endl;
}
}
return 0;
}