C examples for Data Type:int
For example, it would convert 18 days to 2 weeks, 4 days.
Display results in the following format:
18 days are 2 weeks, 4 days.
Use a while loop to allow the user to repeatedly enter day values.
Terminate the loop when the user enters a nonpositive value, such as 0 or minus value.
#include <stdio.h> int main(void) { const int daysperweek = 7; int days, weeks, day_rem; /*from ww w . j a v a2 s . c o m*/ 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; }