题目
编写一个程序,提示用户输入天数,然后将其转换成周数和天数。通过while循环让用户重复输入天数,当用户输入一个非正值时(如0或-20),循环结束。
编程
#include <stdio.h>
int main(void)
{
int days, week, day;
printf("please input days:");
scanf("%d", &days); //输入天数
while (days > 0)
{
week = days / 7;
day = days - week * 7;
printf("%d days is %d week %d day\n", days, week, day);
printf("\nplease input days:");
scanf("%d", &days); //打断while循环,从新输入天数
}
return 0;
}