c program to print advance date (edx course solution ) using structure:

 #include <stdio.h>


struct date {

        int year;

        int month;

        int day;

    };


/* function prototypes */

void printDate(struct date);

void readDate(struct date *);

struct date advanceDay(struct date); 


int main(void) {

struct date today, tomorrow;

readDate(&today);

printf("You Insert:\n");

printDate(today);

printf("Advance Date:\n");

tomorrow = advanceDay(today);

printDate(tomorrow);

return 0;

}

void readDate(struct date *today)

{

    printf("Enter Date in (YYYY/MM/DD) format:\n");

    printf("Enter Year:\n");

    scanf("%d",&today->year);

    printf("Enter Month:\n");

     scanf("%d",&today->month);

     printf("Enter Date:\n");

      scanf("%d",&today->day);

}

void printDate(struct date today)

{

    printf("%02d/%02d/%4d\n",today.month,today.day,today.year);

}


struct date advanceDay( struct date today )

{

    if(today.day==31&&(today.month==1||today.month==3||today.month==5||today.month==7||today.month==8||today.month==10))

    {

        today.month+=1;

        today.day=1;

        

    }

    

    else if(today.day==30&&(today.month==4||today.month==6||today.month==9||today.month==11))

    {

        today.month+=1;

        today.day=1;

    

    }

    

    else if((today.day==28||today.day==29) && today.month==2)

    {

        today.month+=1;

        today.day=1;

        

    }

    else if(today.day==31&&today.month==12)

    {

        today.month=1;

        today.day=1;

        today.year+=1;

       

    }

    

    else

    {

        

        today.day+=1;

       

    }

    

    

    return today;

}






OUTPUT(a);





OUTPUT(b):


Comments

Popular posts from this blog

[ C++ program] Assume that a bank maintains two kinds of accounts for customers, | | one called as savings account and the other as current account. | | The savings account provides compound interest and withdrawal facilities but no cheque book facility. | | The current account provides cheque book facility but no interest. | | Current account holders should also maintain a minimum balance | | and if the balance falls below this level, a service charge is imposed. | | Create a class account that stores customer name, account number and type of account. | | From this derive the classes curacct and savacct to make them more specific to their requirements.

Perform all operation in a singly linked list using C language:

Write a program in C++ to create a base class shape and derive two classes named Circle and Square from it. Create and initialize objects from these classes using appropriate constructors.