answersLogoWhite

0

C programming to display a calendar?

Updated: 8/11/2023
User Avatar

V2re

Lvl 1
12y ago

Best Answer

hmmm. . .

string main () //NOTE you dont have to use the string main or return applepie = )

{

int month, days;

string month_name;

// also if you have to configure the Year i would go by coppying the number of days

//in each month by year and create a massive clause of if else trees by YEAR

// for instance (int year 9)

{

days= 30;

}

}

return applepie;

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include

int IsLeapYear(int);

int DaysPassedFromYear(int, int, int);

int GetNumberOfDaysInMonth(int ,int);

int main()

{

int year=2013, month, i;

for(month=1;month<=12;month++) {

/* This is our start point */

const int firstYear = 1;

int NumDaysInMonth=GetNumberOfDaysInMonth(month,year);

/* 0=Sunday 1=Monday .. 6=Saturday */

int firstDayOfMonth = DaysPassedFromYear(firstYear,month,year) % 7;

/* offsetting so that 1-Sunday,2-monday, etc... */

firstDayOfMonth++;

for(i=1;i

printf(" ");

if(i%7 0 && Year % 100 != 0)) return 1;

return 0;

}

int DaysPassedFromYear(int firstYear, int month,int year)

{

int days, count;

/* per month per year */

int daysPassed[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};

/* The first day of our start year may not be a Sunday... */

const int dayOffset = 3;

/* I think this was first year of leap year... */

const int firstLeapYear = 1804;

/* calculates basic number of days passed */

days = (year - firstYear) * 365;

days += dayOffset;

days += daysPassed[month-1];

/* add on the extra leapdays for past years */

for (count = firstLeapYear; count < year ; count +=4)

if (IsLeapYear(count) ) days++;

/* add leapday for this year if requested month is greater than Feb */

if( month > 2 && IsLeapYear(year) ) days++;

return days;

}

Note: Cleaned up code to shorten it up and properly align output.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include<iostream>

#include<iomanip>

#include<string>

#include<sstream>

#include<cassert>

using std::cout;

using std::cin;

using std::endl;

using std::setw;

using std::string;

using std::stringstream;

#ifndef NDEBUG

#define assert_year(year) do { assert (1900 <= (year)); } while(0)

#define assert_month(month) do { assert ((month) && ((month) <= 12)); } while(0)

#define assert_day(day) do { assert ((day) && ((day) <= 31)); } while(0)

#else

#define assert_year(year) ((void)0)

#define assert_month(month) ((void)0)

#define assert_day(day) ((void)0)

#endif NDEBUG

bool is_leap_year (size_t year)

{

assert_year (year);

if (year%4) return false; // If not a multiple of 4 then common year.

if (year%100) return true; // If a multiple of 4 but not of 100 then leap year.

if (year%400) return false; // If a multiple of 4 and 100 but not of 400 then common year.

return true; // If a multiple of 4, 100 and 400 then leap year.

}

size_t days_in_month (size_t month, size_t year)

{

assert_month (month);

switch (month)

{

case 2:

return is_leap_year (year) ? 28 : 29;

case 4: case 6: case 9: case 11:

return 30;

}

return 31;

}

size_t day_of_year (size_t day, size_t month, size_t year)

{

assert_day (day);

assert_day (month);

size_t days = day;

while (--month)

days += days_in_month (month, year);

return days;

}

size_t days_in_previous_years (size_t year)

{

assert_year (year);

size_t days = 0;

while (1900 < --year)

days += is_leap_year (year) ? 366 : 365;

return days;

};

size_t days_since_epoch (size_t day, size_t month, size_t year)

{

// Epoch is 1st January 1900

return days_in_previous_years (year) + day_of_year (day, month, year) - 1;

}

size_t day_of_week (size_t day, size_t month, size_t year)

{

return days_since_epoch (day, month, year) % 7;

}

void print_calendar (size_t month, size_t year)

{

assert_month (month);

cout << endl;

switch (month)

{

case 1: cout << "January"; break;

case 2: cout << "February"; break;

case 3: cout << "March"; break;

case 4: cout << "April"; break;

case 5: cout << "May"; break;

case 6: cout << "June"; break;

case 7: cout << "July"; break;

case 8: cout << "August"; break;

case 9: cout << "September"; break;

case 10: cout << "October"; break;

case 11: cout << "November"; break;

case 12: cout << "December"; break;

}

cout << ' ' << year << endl;

cout << "\n Su Mo Tu We Th Fr Sa\n";

size_t start_day = day_of_week (1U, month, year);

size_t days = days_in_month (month, year);

size_t count = start_day % 7U + 1U;

for (size_t i = 1; i <= count; i++)

cout << setw (4) << ' ';

for (size_t i = 1; i <= days; ++i)

{

cout << setw (4) << i;

++count;

if (count == 7)

{

cout << endl;

count = 0;

}

}

if (count)

cout << endl;

cout << endl;

}

size_t ask (string prompt)

{

for (;;)

{

cout << prompt;

string input;

cin >> input;

stringstream ss;

ss << input;

size_t reply;

if (ss >> reply)

return reply;

cout << "Invalid input.\n";

}

}

int main (void)

{

for (;;)

{

enter_month:

size_t month = ask ("Enter a month (1 - 12, 0 to exit): ");

if (!month)

break;

if (month > 12)

{

cout << "Invalid month." << endl;

goto enter_month;

}

enter_year:

size_t year = ask ("Enter a year (>= 1900, 0 to exit): ");

if (!year)

break;

if (year < 1900)

{

cout << "Invalid year." << endl;

goto enter_year;

}

print_calendar (month, year);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

void printMonth (int startDay, int days);

int main (void)

{

printfMonth(2,29);

return 0;

}

/*======printMonth===========*/

void printMonth (int startDay, int days)

{

int weekDay;

int dayCount = 0;

{

printf("Sun Mon Tue Wed Thu Fri Sat\n");

printf("--- --- --- --- --- --- ---\n");

for (weekDay= 0; weekDay < startDay; weekDay++)

{printf(" ");}

for (int dayCount = 1; dayCount <= days; dayCount++)

{

if (weekDay > 6)

{

printf("\n");

weekDay = 1;

}

else

weekDay++;

printf("%3d", daycount);

}

printf("\n--- --- --- --- --- --- ---\n");

return;

}}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

It is a calender application in c language.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C programming to display a calendar?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write c programs to display 10 line biodata?

A C++ program can be used to write C programs that will display 10 lines of biodata. Many types of C programming can be written with a C++ program.


What is c and c in computer programming?

C and C++ are both high-level programming languages.


Create a spiral in C programming?

create spiral in c programming?


How did you get the days of the week for the calendar?

Different webaites provide option to display week number in calendar.


How do you display 'hello world' using c programming language?

#include&lt;stdio.h&gt; int main (void) { printf ("Hello world!\n"); return 0; }


What has the author Robert Lafore written?

Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming


When was C - programming language - created?

C - programming language - was created in 1972.


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.


What is the programming language used to display webpages?

What_is_the_language_used_for_creating_web_pages


What is the benefit of the C programming languages?

C language is better for hardware programming .Most of the programming for hardware are written in C language so it is beneficial for hardware programming is not efficient for application programming due to drawback like in C data moves around the system.


Name of object oriented programming language?

C++ is the name of a programming language.


Where can one find C programming tutorials?

You can find C programming tutorials online at the C programming website. They provide both free and paid tutorials for many aspects of the C and C++ code.