Computer Science, asked by Palandr4477, 7 months ago

Write a c program to create a structure named date having day, month and year as its elements. store the current date. now add 15 days to the current date and display the "same month" if the addition of days is within the month, otherwise display "next month"..


input format:


line contains date in dd mm yyyy format


input:


12 03 2020


output:


same month

Answers

Answered by abhishekmishra737007
3

Answer:

input format:

line contains date in dd mm yyyy format

input:

12 03 2020

output:

same month

Answered by mindfulmaisel
1

program to create a structure named date

Explanation:

#include <time.h>

// Function for applying adding days

void DatePlusDays( struct tm* date, int days )

{

   const time_t ONE_DAY = 24 * 60 * 60 ;

   time_t date_seconds = mktime( date ) + (days * ONE_DAY) ;

   *date = *localtime( &date_seconds ) ; ;

}

#include <stdio.h>

int main()

{

   int day=26, month=2 , year=2010;

   printf("Enter Date Month Year: ");

   scanf("%d %d %d", &day, &month, &year);

   struct tm date = { 0, 0, 12 } ;  // nominal time midday (arbitrary).

   // Set up the date structure

   date.tm_year = year - 1900 ;

   date.tm_mon = month - 1 ;  // note: zero indexed

   date.tm_mday = day ;       // note: not zero indexed

   DatePlusDays( &date, 15 ) ;

   if(date.tm_mon+1 == month){

       printf("same month\n");

   }else{

       printf("next month\n");

   }

}

Similar questions