Program to find out the number of days in entered month

//Program to find out the number of days in entered month
#include<stdio.h>
#include<conio.h>
int main()
{
  int m,y;
  clrscr();
  printf("Enter the Month no. and Year\n");
  scanf("%d%d",&m,&y);
  switch(m)
  {
    case 1:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("January has 31 days and Year has 366 days");
    else printf("January has 31 days and Year has 365 days");
    break;

    case 2:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("February has 29 days and Year has 366 days");
    else printf("February has 28 days and Year has 365 days");
    break;

    case 3:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("March has 31 days and Year has 366 days");
    else printf("March has 31 days and Year has 365 days");
    break;

    case 4:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("April has 30 days and Year has 366 days");
    else printf("April has 30 days and Year has 365 days");
    break;

    case 5:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("May has 31 days and Year has 366 days");
    else printf("May has 31 days and Year has 365 days");
    break;

    case 6:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("June has 30 days and Year has 366 days");
    else printf("June has 30 days and Year has 365 days");
    break;

    case 7:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("July has 31 days and Year has 366 days");
    else printf("July has 31 days and Year has 365 days");
    break;

    case 8:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("August has 31 days and Year has 366 days");
    else printf("January has 31 days and Year has 365 days");
    break;

    case 9:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("September has 30 days and Year has 366 days");
    else printf("September has 30 days and Year has 365 days");
    break;

    case 10:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("October has 31 days and Year has 366 days");
    else printf("October has 31 days and Year has 365 days");
    break;

    case 11:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("November has 30 days and Year has 366 days");
    else printf("November has 30 days and Year has 365 days");
    break;

    case 12:
    if(y%4==0&&y%100!=0||y%400==0)
    printf("December has 31 days and Year has 366 days");
    else printf("December has 31 days and Year has 365 days");
    break;

    }
  getch();
  return 0;
}

To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

No comments:

Post a Comment