Input a date using C program and check if it is valid. Print messages accordingly - counter
Sponsored Links


Popular Links


List of Abbreviations

National Highways in India

States & Union Territories of India

Currency of All Countries

Input a date using C program and check if it is valid. Print messages accordingly

You are Here: Home > Computer Subjects > Programming in C Language > …

Input a date using C program and check if it is valid. Print messages accordingly.

Ans.

     main()
     {
          int d, m, y, l;

          printf(“accept date in dd mm yy”);
          scanf(“%d%d%d”,&d,&m,&y);

          switch(m)
          {
            case1:
            case3:
            case5:
            case7:
            case8:
            case10:
            case12:
                          l=31;
                          break;
            case4:
            case6:
            case9:
            case11:
                          l=30;
                          break;
            case2:
                         if((y%4)==0)
                             l=29;
                         else
                             l=28;

                         break;
          }

          if(((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12)) && (d<=l))
          {
              printf(“valid”);
          }
          else if(((m==4)||(m==6)||(m==9)||(m==11) && (d<=l)))
          {
              printf(“valid”);
          }
          else
          {
              printf(“invalid”);
          }
     }

Click Here to Find Latest Jobs and Current Affairs
Updated: May 31, 2013 — 2:05 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2016. All Rights Reserved. WikiIND.com