Sample C Program to convert given number of days to a measure of time given in years, weeks and days.
For example 375 days is equal to 1 year 1 week and 3 days (ignore leap year).
# include <stdio.h>
#define DAYSINWEEK 7
void main()
{
int ndays, year, week, days;
printf("Enter the number of daysn");
scanf("%d", &ndays);
year = ndays / 365;
week =(ndays % 365) / DAYSINWEEK;
days =(ndays % 365) % DAYSINWEEK;
printf ("%d is equivalent to %d years, %d weeks and %d days", ndays, year, week, days);
}
Output:
Enter the number of days
29
29 is equivalent to 0 years, 4 weeks and 1 days
Enter the number of days
1000
1000 is equivalent to 2 years, 38 weeks and 4 days
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com