Home>
I would like to find the number of days elapsed from January 1, 1900 to January 1, X, taking into account the leap year.
If i compare the results with this site, it may sometimes be off by one day. I don't know where the problem is. Corresponding source code#include<iostream>
int main ()
{
int year;
std :: cin >>year;
int day {0};
int a, b, c, d, e;
a = year1900;
b = 365 * a;
c = a/4;
d = a/100;
e = a/400;
day + = b;
day + = c;
day= d;
day + = e;
std :: cout<<day;
return 0;
}

Answer # 1

Answer # 2
The leap year calculation is strange
1900 is not divisible by 400Let's check the definition of leap year

Answer # 3
I don't know where the problem is.
At least one point. The year 2000 is a leap year because it is divisible by 400. Therefore, entering 2001 should add one day. However, in the code
a = year 1900;// 2001 1900 = 101 ... e = a/400; ... day + = e;
Since it is, one day of the leap year of 2000 will not be added.On the referenced site, you can select either "Do not include or include the first day", but I do not know which one the questioner's code wants to fit, so I will only answer the above points.

Answer # 4
Try changing it as follows:
c = a/4; d = a/100; e = a/400 + c = (a + 3)/4; + d = (a + 99)/100; + e = (a + 299)/400;
Do you get the results you expect?
Related articles
 calculation of addition of all c ++ combinations and the number of combinations
 error in c ++ double calculation
 c ++  calculation result is not output
 c ++  i want to be able to input character strings and number strings in the scanf part
 python  the calculation of the difference in the number of days by relativedelta is a few days different from the result calcul
 c ++  on the inverse element calculation using the extended euclidean algorithm
 calculation of the number of powers of 2
 c ++  what causes the calculation result to be 0?
 calculation of the number of same numbers
 c ++  i want to count the number of same characters
 c ++  the calculation result of the matrix is strange
 c ++  what does it mean to specify threads that exceed the number of cpu cores/threads in multithreading?
 javascript  calculation of the difference between the elapsed time and the set target time
 c ++  about getting the number of elements in a twodimensional array
 c ++  i want to get the number of elements of the array taken as the argument of the function
 c ++  i would like to know the calculation formula for pasting uv coordinates on the entire cube
 i counted the number of days elapsed with python
 c ++  the number entered when displaying the result will be 0
 c ++  random number generation in loop processing
Trends
 python  you may need to restart the kernel to use updated packages error
 php  coincheck api authentication doesn't work
 php  i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
 [php] i want to get account information using coincheck api
 the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
 javascript  how to check if an element exists in puppeteer
 i want to call a child component method from a parent in vuejs
 python 3x  typeerror: 'method' object is not subscriptable
 dart  flutter: the instance member'stars' can't be accessed in an initializer error
 xcode  pod install [!] no `podfile 'found in the project directory
Although it depends on the answers and contents of other people
Years that are divisible by 400 after 1900 are, for example, 2000, 2400.
However, if you judge whether it is divisible by 400 after subtracting 1900, 2300, 2700 ,,, will be applicable, and since it is divisible by 400, the year to add one day to become a leap year will be 300 years different from the actual year.