您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

编写一个C程序,将给定的天数转换为年、周和天

2024/2/17 17:28:29发布22次查看
给定了天数,任务是将给定的天数转换为年、周和天。
让我们假设一年中的天数 =365
年数=(天数)/365
解释-:年数将是除以给定天数得到的商与 365
周数 = (天数 % 365) / 7
解释-:周数将通过收集余数获得将天数除以 365,再除以一周的天数 7。
天数 = (天数 % 365) % 7
说明-:天数是用天数除以365所得的余数再除以一周的天数7得到的余数。
示例input-:days = 209output-: years = 0 weeks = 29 days = 6input-: days = 1000output-: years = 2 weeks = 38 days = 4
算法startstep 1-> declare macro for number of days as const int n=7step 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 daysstep 3-> in main() declare int total_days = 209 call find(total_days)stop
example 现场演示
#include <stdio.h>const int n=7 ;//find year, week, daysvoid 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;}
输出如果我们运行上述代码,它将生成以下输出
years = 0weeks = 29days = 6
以上就是编写一个c程序,将给定的天数转换为年、周和天的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product