Tuesday, 8 March 2011

Write program to accept number of days and print year, month and remaining days

#include<stdio.h>
#include<conio.h>
int main()
{
int day,y,m; /*day for day input & output,
y for calculate year,
m for calculate month
printf("Enter the number of days : ");
scanf("%d",&day);
y=day/365; //calculate years
day%=365; // calculate remaining days
m=day/30; // calculate months
day%=30; // calculate remaining days
printf("%d years,%d months, %d days",y,m,day);
getch();
return 0;
}
Output:
Enter number of days : 1025
2 years,9 months, 25 days

No comments:

Post a Comment