# C program to convert a given number of days into days, weeks, and years

Here, we are going to learn how to convert a given number of days into days, weeks, and years in C programming language?
Submitted by Nidhi, on July 22, 2021

## Problem statement

Read the number of days from the user and convert it to years, weeks, and days using C program.

## C program to convert a given number of days into days, weeks, and years

The source code to convert the given number of days into days, weeks, and years is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

```// C program to convert a given number of days into
// days, weeks, and years

#include <stdio.h>

int main()
{
int ndays = 0;
int years = 0;
int weeks = 0;
int days = 0;

printf("Enter days: ");
scanf("%d", &ndays);

years = ndays / 365;
weeks = (ndays % 365) / 7;
days = (ndays % 365) % 7;

printf("%d years, %d weeks and %d days\n", years, weeks, days);

return 0;
}
```

### Output

```RUN 1:
Enter days: 367
1 years, 0 weeks and 2 days

RUN 2:
Enter days: 1280
3 years, 26 weeks and 3 day

RUN 3:
Enter days: 11
0 years, 1 weeks and 4 days
```

### Explanation

In the above program, we created 4 integer variables ndays, years, weeks, days that are initialized with 0. Then we read the number of days from the user and convert it into years, weeks, days, and printed them on the console screen.

Comments and Discussions!

Student's Section
Subscribe

Copyright © 2024 www.includehelp.com. All rights reserved.