例如,它会将18天转换为2周,4天。

以下列格式显示结果:

18天是2周,4天。

使用while循环允许用户重复输入日期值。

当用户输入非正值(例如0或负值)时终止循环。

#include <stdio.h>  

int main(void) {  
    const int daysperweek = 7;  
    int days, weeks, day_rem;  
    printf("Enter the number of days: ");  
    scanf("%d", &days);  
    while (days > 0)  
    {  
        weeks = days / daysperweek;  
        day_rem = days % daysperweek;  
        printf("%d days are %d weeks and %d days.\n",  days, weeks, day_rem);  

        printf("Enter the number of days (0 or less to end): ");  
        scanf("%d", &days);  
    }  
    printf("Done!\n");  
    return 0;  
}