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

WBOY
Release: 2023-09-01 23:45:07
forward
564 people have browsed it

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

Given the number of days, the task is to convert the given number of days into years, weeks and days.

Let us assume the number of days in a year = 365

Number of years = (number of days)/365

Explanation-: The number of years will be divided by giving The quotient of a given number of days and 365

number of weeks = (number of days % 365) / 7

Explanation-: The number of weeks will be obtained by collecting the remainder and dividing the number of days by 365 , divided by the number of days in the week, 7.

Number of days = (Number of days % 365) % 7

Explanation-: The number of days is the remainder obtained by dividing the number of days by 365 and then dividing the remainder by the number of days in the week 7 .

Example

Input-:days = 209 Output-: years = 0 weeks = 29 days = 6 Input-: days = 1000 Output-: years = 2 weeks = 38 days = 4
Copy after login

Algorithm

Start Step 1-> declare macro for number of days as const int n=7 Step 2-> Declare function to convert number of days in terms of Years, Weeks and Days void find(int total_days) declare variables as int year, weeks, days Set year = total_days / 365 Set weeks = (total_days % 365) / n Set days = (total_days % 365) % n Print year, weeks and days Step 3-> in main() Declare int Total_days = 209 Call find(Total_days) Stop
Copy after login

Example

Live demonstration

#include  const int n=7 ; //find year, week, days void find(int total_days) { int year, weeks, days; // assuming its not a leap year year = total_days / 365; weeks = (total_days % 365) / n; days = (total_days % 365) % n; printf("years = %d",year); printf("

weeks = %d", weeks); printf("

days = %d ",days); } int main() { int Total_days = 209; find(Total_days); return 0; }

Copy after login

Output

If we run the above code , it will generate the following output

years = 0 weeks = 29 days = 6
Copy after login

The above is the detailed content of Write a C program to convert a given number of days into years, weeks and days. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!