Welcome to Westonci.ca, where curiosity meets expertise. Ask any question and receive fast, accurate answers from our knowledgeable community. Ask your questions and receive accurate answers from professionals with extensive experience in various fields on our platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
Sagot :
Using the knowledge of computational language in python we can write the code as function, daysbewteen, which returns an integer representing the numbers of days between two dates.
Writting the code:
#include <iostream>
using namespace std;
int daysInMonth(int month, int year) //function to know the days in a month
{
//array to store the days of each month for a non-leap year
int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//array to store the days of each month for a leap year
int a2[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) //if the year is a leap year
return a2[month-1]; //value from a2 array is returned
else //else if the year is not a leap year
return a1[month-1]; //value from a1 array is returned
}
int daysBetween(int y1, int m1, int d1, int y2, int m2, int d2) //function definition
{
int days = 0; //days is initialized to zero
for(int i = y1; i <= y2; i++) //for each year from y1 to y2 loop repeats
{
if(i == y1) //if i equals to y1
{
days = days + daysInMonth(m1, y1) - d1; //for m1 days is calculated and subtract d1 from that
for(int j = m1+1; j <= 12; j++) //from the months starting m1+1
{
days = days + daysInMonth(j, i); //days in each month is added to days variable
}
}
else if(i == y2) //if i equals to y2
{
days = days + d2; //d2 is added to days
for(int j = 1; j < m2; j++) //we can only check upto m2-1 month
days = days + daysInMonth(j, i); //days in each month is added to days
}
else //else
for(int j = 1; j <= 12; j++) //for each month in that year
days = days + daysInMonth(j, i); //days in that month is added to days
}
return days; //days is returned
}
int main() //main function
{
int y1, m1, d1, y2, m2, d2; //variable declarations
cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2; //reads the input
cout << daysBetween(y1, m1, d1, y2, m2, d2); //calls the function and prints returned value
return 0;
}
See more about C++ at brainly.com/question/19705654
#SPJ1
Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Westonci.ca is your go-to source for reliable answers. Return soon for more expert insights.