Sunday, 24 April 2022

4. Define a structure to represent a date. Use your structures that accept two different dates in the format mm dd of the same year. Write a C program to display the month names of both dates.

 


#include<stdio.h>
#include<conio.h>

struct date
{
    int dd,mm,yy;
}s[2];

void main()
{
    int i;
    clrscr();
    printf("!! enter two date MM and DD format of the same year !!");

    for(i=0; i<2; i++)
    {
        printf("\n\nenter date %d DD: ",i+1);
        scanf("%d",&s[i].dd);
        if(s[i].dd>=32)
        {
            printf("\n\n!! enter valid date !!");
            getch();
            exit(0);
        }
        printf("enter date %d mm: ",i+1);
        scanf("%d",&s[i].mm);
        if(s[i].mm>=13)
        {
            printf("\n\n!! enter valid month !!");
            getch();
            exit(0);
        }

        printf("enter date %d yy: ",i+1);
        scanf("%d",&s[i].yy);
        if(i==1)
        {
            if(s[0].yy != s[1].yy)
            {
                printf("\n\n!! please enter same year of both dates !!");
                getch();
                exit(0);
            }
        }
    }
    for(i=0; i<2; i++)
    {
    switch(s[i].mm)
    {
    case 1: printf("\n%d date %d-%d-%d month: january\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 2: printf("\n%d date %d-%d-%d month: february\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;
           
    case 3: printf("\n%d date %d-%d-%d month: march\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 4: printf("\n%d date %d-%d-%d month: april\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 5: printf("\n%d date %d-%d-%d month: may\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 6: printf("\n%d date %d-%d-%d month: june\n",    
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 7: printf("\n%d date %d-%d-%d month: july\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 8: printf("\n%d date %d-%d-%d month: august\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 9: printf("\n%d date %d-%d-%d month: september\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 10: printf("\n%d date %d-%d-%d month: octomber\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 11: printf("\n%d date %d-%d-%d month: navember\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;

    case 12: printf("\n%d date %d-%d-%d month: december\n",
            i+1,s[i].dd,s[i].mm,s[i].yy);
    break;
    }
    }
    getch();
}

/*  output:

!! enter two date MM and DD format of the same year !!
                                                                               
enter date 1 DD: 31                                                            
enter date 1 mm: 1                                                              
enter date 1 yy: 2004                                                          
                                                                               
                                                                               
enter date 2 DD: 13                                                            
enter date 2 mm: 10                                                            
enter date 2 yy: 2004                                                          
                                                                               
1 date 31-1-2004 month: january                                                
                                                                               
2 date 13-10-2004 month: octomber                                              
                                                                               
*/

No comments:

Post a Comment

python programs

1. sum of two number