
给定了天数,任务是将给定的天数转换为年、周和天。
让我们假设一年中的天数 =365
年数=(天数)/365
解释-:年数将是除以给定天数得到的商与 365
周数 = (天数 % 365) / 7
解释-:周数将通过收集余数获得将天数除以 365,再除以一周的天数 7。
天数 = (天数 % 365) % 7
说明-:天数是用天数除以365所得的余数再除以一周的天数7得到的余数。
Input-:days = 209 Output-: years = 0 weeks = 29 days = 6 Input-: days = 1000 Output-: years = 2 weeks = 38 days = 4
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现场演示
#include <stdio.h>
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("</p><p>weeks = %d", weeks);
printf("</p><p>days = %d ",days);
}
int main() {
int Total_days = 209;
find(Total_days);
return 0;
}如果我们运行上述代码,它将生成以下输出
years = 0 weeks = 29 days = 6
以上就是编写一个C程序,将给定的天数转换为年、周和天的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号