# 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 Solution:

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

Program:

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.

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates