Assignments » Variable, Operator and Expression » Set2 » Solution 5

Write a program which accepts days as integer and display total number of years, months and days in it.



#include<iostream>
using namespace std;

int main()
{
	int days,y,m,d;
	cout<<"Enter no. of days : ";
	cin>>days;
	y=days/365;
	days=days%365;
	m=days/30;
	d=days%30;
	cout<<"Years : "<<y<<"\nMonths : "<<m<<"\nDays : "<<d;

	
	return 0;
}

Enter no. of days : 796
Years : 2
Months : 2
Days : 6