The task is simple: Find the number of days between two dates. Provide account leap years.
To practice the two options:
- One of the boundary dates described only a year. That is, the start date is entered in full (for example 25.12.2015), and the second only a year (for example 2016). It counts the days before 01.01.2016
- Both the date of full – describes day month year.
Here is an example of a, partially crucial first simplified version:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <iostream> using namespace std; int DaysCount(int yearBegin, int monthBegin, int dayBegin, int yearCurrent){ int y, m, e, d, a, b, c, res = 0; a = yearCurrent - yearBegin; // Разница в годах b = a / 4; // Кол-во високосных c = a - b; // Кол-во невысокосных d = b * 366 + c * 365; // Предварительное кол-во дней до начала года d -= (yearCurrent % 4) ? 1 : 0; // +1 день, если год високосный // Считаем месяцы for (e = 1; e < monthBegin; e++) { // Если февраль и високосный: if (e == 2) d -= (yearCurrent % 4) ? 28 : 29; // Если по 30 дней else if (e == 4 || e == 6 || e == 9 || e == 11) d -= 30; else // Если по 31 день в месяце d -= 31; }; /* Для корректировки, если расчет идет от последнего месяца года до задаваемого граничного года можно использовать примерно такое условие, дабы не прибавлять, а вычитать количество дней */ if (monthBegin != 12 && a == 1) return dayBegin + d; else return d - dayBegin; } int main() { cout << DaysCount(2015, 12, 15, 2016) << endl; } |
Here the function DaysCount() It receives in the first three parameters of the start date (year, month, day) and the last parameter boundary (year, 1-th day of January,)
Solve any possible way, even though the cycle with something else. But the decision of the second embodiment does not show :) Let it be homework. Good luck!
Questions to ask in the comments
please help to write a program
Determine how many days in a year (Total 12 months, each has a certain number of days) using a function for, and one-dimensional array
[code]#include “stdafx.h”
#include
using namespace std;
int main()
{
int monthM[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
char ch;
int end, day, month, year, sum = 0;
setlocale(LC_ALL, “rus”);
cout <> day >> ch >> month >> ch >> year;
cout<> end;
for (int i = month + 1;i <= 11;i ) sum += monthM[i];
sum += monthM[month]+day + (end – year) * 365;
for (int i = year+1; i < end; i )
if (i % 400 == 0 || i % 4 == 0) sum++;//Wikipedia is written, that in the Gregorian calendar leap year every 4th + each 400y
if ((year % 400 == 0 || year % 4 == 0) && month < 4) sum++; //starting year checking separately, tk. even if it is a leap year, we can not catch 29fevralya during
cout << "\nВ этом промежутке " << sum << "дней!";
return 0;
}
[/code]
2 – Fragments of advertising blocks – 12.06.2003
Video from Thursday, 12 June 2003 r.
2 – Fragment of an advertising block – 20.11.2000
Video from Monday, 20 November 2000 r.
1 – Two advertising blocks and announcements, ident – 20.07.2010
Video from Tuesday, 20 July 2010 r.
Two advertising blocks and announcements, social announcement and spot, for audios – 24.09.2008
Wednesday's footage, 24 September 2008 r.
2 – Fragments of advertising blocks – 24.04.2013
Wednesday's footage, 24 April 2013 r.
Advertising block and announcements (Россия, 19.12.2009) (1)
1 – Fragments of advertising blocks – 27.01.2012
Recording from Friday, 27 January 2012 r.
1 – Fragments of advertising blocks – 28.09.2014
Footage from Sunday, 28 September 2014 r.
2 – Two advertising blocks and announcements, social announcement and spot, for audios – 24.04.2012
Video from Tuesday, 24 April 2012 r.
Two advertising blocks and announcements, social announcement and spot, for audios – 27.11.2009
Recording from Friday, 27 November 2009 r.
2 – Fragments of advertising blocks – 24.10.2011
Video from Monday, 24 October 2011 r.
News (Россия, 20.12.2009)
Announcement and Ad block (Россия, 28.11.2009)
Announcement and Ad block (Russia-1, 14.10.2012)
TVP 1 – advertisements and announcements – Friday 25.11.2011
News (Россия, 20.11.2008)
News (Russia-1, 11.12.2011)
1 – Two advertising blocks and announcements, ident – 24.12.2000
Footage from Sunday, 24 of December 2000 r.
Advertising block and announcement (Россия, 19.12.2009) (2)
TV program with 10 по 16 October 2011 g. D. Kokshetau, Kazakhstan
Воскресенье, 16 October 2011 g.
Kazakhstan
Message
Channel One Eurasia
El-Arna
Astana
Kazakhstan-Kokshetau
CTC
NTC
7 channel
Noble channel
TV program for the week 29.05.2011, vs
Kazakhstan
Message
El-Arna
Channel One Eurasia
CTC
NTC
31 channel
First channel
Россия 1
NTV
REN-TV
TV program with 21 по 27 Martha 2011 g. D. Kokshetau, Kazakhstan
Четверг, 24 Martha 2011 g.
Kazakhstan
Message
Channel One Eurasia
El-Arna
Astana
Kazakhstan-Kokshetau
CTC
NTC
31 channel
7 channel
STV
Hit TV
Noble channel
TV program Kazakhstan truth for a week 10.02.2012, pt
Kazakhstan
Message
El-Arna
Chick