Thursday 17 March 2016

WAP in C to calculate/extract years, weeks and remaining days

#include <stdio.h>
#include<conio.h>
#define daysinaweek 7

void main()
{
      int no_of_days, days, weeks, years; // required variables
      clrscr(); //clearing the console screen

      printf("Enter the number of days: \n");
      scanf("%d" , &no_of_days); //taking input in form of days

      years = no_of_days / 365; //extracting years
      weeks = (no_of_days % 365) / daysinaweek ; // extracting weeks
      days = (no_of_days % 365) %  daysinaweek ; // remaining days

//Output required

      printf ("%d is equivalent to %d years, %d weeks and %d days\n", no_of_days, years, weeks, days);
}

No comments:

Post a Comment