This a C program which converts a given number of Days in terms of years, weeks & days.
This program takes the number of days as input and converts in terms of years, weeks & days.
1. Take the number of days as input.
2. For the number of years, divide the input by 365 and obtain its quotient.
3. For the number of weeks, divide the input by 365 and obtain its remainder.Further divide the remainder by 7(no of days in a week) and obtain its quotient.
4. For the number of days, divide the input by 365 and obtain its remainder.Further divide the remainder by 7(no of days in a week) and obtain its remainder.
Here is source code of the C program to converts a given number of Days in terms of years, weeks & days. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* 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 days\n");
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 daysn",
ndays, year, week, days);
}
1. Take the number of days as input and store it in variable ndays.
2. For the number of years, divide the input by 365(no of days in a year) and obtain its quotient.Store this in the variable year.
3. For the number of weeks, divide the input by 365 and obtain its remainder.Further divide the remainder by 7(no of days in a week) and obtain its quotient.Store this in the variable week.
4. For the number of days, divide the input by 365 and obtain its remainder.Further divide the remainder by 7(no of days in a week) and obtain its remainder.Store this in the variable days.
5. Print the output and exit.
Case:1 Enter the number of days 29 29 is equivalent to 0 years, 4 weeks and 1 days Case:2 Enter the number of days 1000 1000 is equivalent to 2 years, 38 weeks and 4 days
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Check Computer Science Books
- Check C Books
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Apply for C Internship