Q:

Program to convert days into years

belongs to collection: Basic Programs

0

Explanation

Well, we know that one year is the sum of 365 days(non-leap year). So the basic formula to convert days into years is to divide the number of days by number(365).

Number of years = (Number of days ) / 365

Algorithm

  1. Define the number of days to convert into years.
  2. Apply in the formula.
  3. Print the number of years.

Complexity

O(1)

Input:

days799;  

Output:

Number of years = days / 365;
                = 799 / 365
                = 2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Python

days= 5555  
years= days / 365  
print("Number of years is: ");  
print(years);  

 

Output:

Number of years is: 15

 

C

#include<stdio.h>  
                   int main()   
                   { int days, years;  
                   days= 543;  
                   years=  days / 365;   
                   printf("\n\n Number of years is : %d",years);  
                   return (0);  
    }  

 

Output:

Number of years is: 1

 

JAVA

public class Main  
 {  
   public static void main (String args[])  
    {   int days, years;  
                         days = 799;  
                         years = days / 365;  
                         System.out.println("Number of years is:"+years);  
    }}  

 

Output:

Number of years is: 2

C#

using System;  
class main  
{   static void Main()   
    {  
      int days, years;   
      days =6788;  
      years = days / 365;  
       Console.WriteLine("Number of years is: "+years);  
    }}  

 

Output:

Number of years is: 18

 

PHP

<?php  
       $days = 4446 ;  
       $years = ($days)/365 ;   
       echo("Number of years is:  ");  
       echo($years);  
?>

  

Output:

Number of years is:  12

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to convert Fahrenheit into Celsius... >>
<< Program to convert Celsius into Fahrenheit...