Program to find Number of days in a given month of a given year

Program to find Number of days in a given month of a given year

10 May 2023

10 May 2023

Write a program to find Number of days in a given month of a given year



Description about Program to find Number of days in a given month of a given year

Get the number of month and year as input from the user and check the number of days present in that month.

Input

Enter month: 2

Enter year: 2000

Output

29


C Program to find Number of days in a given month of a given year???????

#include<stdio.h> 

int main()

{

    int month, year;

    printf("enter month : ");

    scanf("%d",&month);

    printf("enter year : ");

    scanf("%d",&year);

    if(((month==2) && (year%400==0)) || ((year%100!=0)&&(year%4==0)))

    {

        printf("Number of days is 29");

    }

    else if(month==2)

    {

        printf("Number of days is 28");

    }

    else if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)

    {

        printf("Number of days is 31");

    }

    else

    {

        printf("Number of days is 30");

    }

    return 0;

}


C++ Program to find Number of days in a given month of a given year???????

#include <iostream>

using namespace std;

int main()

{

    int month, year;

    cout<<"enter month : ";

    cin>>month;

    cout<<"enter year : ";

    cin>>year;

    if(((month==2) && (year%400==0)) || ((year%100!=0)&&(year%4==0)))

    {

        cout<<"Number of days is 29";

    }

    else if(month==2)

    {

        cout<<"Number of days is 28";

    }

    else if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)

    {

        cout<<"Number of days is 31";

    }

    else

    {

        cout<<"Number of days is 30";

    }

    return 0;

}


Java Program to find Number of days in a given month of a given year???????

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

int month, year;

    Scanner sc = new Scanner(System.in);

    System.out.println("enter the month and year: ");

    month=sc.nextInt();

    year=sc.nextInt();

    if(((month==2) && (year%400==0)) || ((year%100!=0)&&(year%4==0)))

    {

        System.out.println("Number of days is 29");

    }

    else if(month==2)

    {

        System.out.println("Number of days is 28");

    }

    else if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)

    {

        System.out.println("Number of days is 31");

    }

    else

    {

        System.out.println("Number of days is 30");

    }

}

}


Python Program to find Number of days in a given month of a given year???????

month = int(input('Enter the month: '))

year = int(input('Enter the year: '))

if(month == 2 and (year%400 == 0) or ((year%100 != 0) and (year%4 == 0))):

    print('Number of days is 29')

elif(month == 2):

    print('Number of days is 28')

elif(month == 1 or Month == 3 or Month == 5 or Month == 7 or Month == 8 or Month == 10 or Month == 12):

    print('Number of days is 31')

else:

    print('Number of days is 30')


: Page 1 - started


Related Articles

Ask Us Anything !