C 模和余数
嘿,我正在努力弄清楚如何显示这个结果。举例来说,我输入一个数字,例如 59。根据该数字,我得到的剩余结果为 1 周 2 天 5 小时。当然,为了获得该输出,这是假设一周有 40 小时、1 天有 7 小时。任何朝着正确方向的帮助都会有所帮助。到目前为止,我已经将其设置如下:
scanf("%d %d %d", &totalWeeksWorked, &totalDaysWorked, &totalHoursWorked);
Hey, I'm having the toughest time figuring out how to display this result. Say for example I enter a number such as 59. Based off that number, I get a remaining result of 1 week(s) 2 Day(s) and 5 Hour(s). This is of course assuming one week has 40 hours and 1 day has 7 hours in order to get that output. Any help in the right direction would be helpful. So far I've set it up like so:
scanf("%d %d %d", &totalWeeksWorked, &totalDaysWorked, &totalHoursWorked);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是最快的方法,但可能是最具说明性的:
使用模数:
然后按照您想要的方式显示它们。
This is not the fastest way, but is perhaps the most illustrative:
Using modulo:
Then display them how you want.