Read the number of days and then converts that value to weeks and days. - C Operator

C examples for Operator:Arithmetic Operator

Introduction

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 -20.

Demo Code

#include <stdio.h>

const int DAYS_PER_WEEK = 7;

int main(void)
{
  int days;/*from ww  w .  ja  v a  2  s.  c  om*/

  printf("Enter a number of days (or enter 0 to quit): ");
  scanf("%d", &days);
  while (days > 0)
  {
    printf("%d days are %d weeks, %d days.\n", days, days / DAYS_PER_WEEK,
           days % DAYS_PER_WEEK);

    printf("Enter a number of days (or enter 0 to quit): ");
    scanf("%d", &days);
  }

  return 0;
}

Result


Related Tutorials