Program to convert Days into years, months and Weeks

Problem statement:- Program to convert Days into years, months, and Weeks.

Data requirement:-

   Input Data:-days

  Output Data:-
years, weeks, months

Program in C

Here is the source code of the C Program to convert Days into years, months, and Weeks.

Code:

#include<stdio.h>
int main()
{
   int days, years, weeks, months;
   printf("Enter Days:");
   scanf("%d",&days);

   years=days/365;
   weeks=days/7;
   months=days/30;

   printf("Days to years %d",years);
   printf("\nDays to weeks %d",weeks);
   printf("\nDays to months %d",months);
}


Input/Output:
Enter Days:365
Days to years 1
Days to weeks 52
Days to months 12






Program in C++

Here is the source code of the C++ Program to convert Days into years, months, and Weeks.

Code:

#include<iostream>
using namespace std;
int main()
{
   int days, years, weeks, months;
   cout<<"Enter Days:";
   cin>>days;
   years=days/365;
   weeks=days/7;
   months=days/30;

   cout<<"Days to years:"<<years;

   cout<<"\nDays to weeks :"<<weeks;
   cout<<"\nDays to months :"<<months;
}

Input/Output:
Enter Days:730
Days to years: 2
Days to weeks: 104
Days to months: 24

Program in Java

Here is the source code of the Java Program to convert Days into years, months, and Weeks.

Code:

import java.util.Scanner;
public class DaysToYearMonthWeak {

public static void main(String[] args) {

Scanner cs=new Scanner(System.in);
int days, years, weeks, months;
System.out.println("Enter Days:");
   days=cs.nextInt();
   years=days/365;
   weeks=days/7;
   months=days/30;

   System.out.println("Days to years "+years);
   System.out.println("Days to weeks "+weeks);
   System.out.println("Days to months "+months);
         
   cs.close();
}
}

Input/Output:
Enter Days:
1095
Days to years 3
Days to weeks 156
Days to months 36

Program in Python

Here is the source code of the Python Program to convert Days into years, months, and Weeks.

Code:

days=int(input("Enter Day:"))

years =(int) (days / 365)
weeks =(int) (days / 7)
months =(int) (days / 30)

print("Days to Years:",years)
print("Days to Weeks:",weeks)
print("Days to Months:",months)

Input/Output:
Enter Day:1825
Days to Years: 5
Days to Weeks: 260
Days to Months: 60

Post a Comment

1 Comments

  1. in python, if input is 1822 , code gives us : 4 years 12 moths and 2 days
    but the correct is 4 years 11 months 27 days
    so how we fix it ?

    ReplyDelete

Please do not Enter any spam link in the comment box