C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to convert days into years
ExplanationWell, 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
ComplexityO(1) SolutionPython
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
Next Topic#
|