[C/C++] Convert Given Number of Days into Years, Weeks and Days

Program to convert given number of days into years, weeks and days

  1. Get number of days from user
  2. Divide number of days with 365 to get number of years
  3. For week take mod with 365 days and divide it with 7 you’ll get weeks
  4. And for days take mod with 365 and then take mode with 7 you’ll get days

C Code

#include <stdio.h>
#include<conio.h>

int main()
{
 int y,w,d,a;
 clrscr(); 
 printf("Enter total number of days:");
 scanf("%d",&d);
 
 y=d/365;
 a=d%365;
 w=a/7;
 d=a%7;
 
 printf("\nYears: %d\nWeeks: %d\nDays: %d",y,w,d);
 
 getch(); 
}

C++ Code

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
 int y,w,d,a;
 cout << "Enter total number of days: ";
 cin >> d;
 
 y=d/365;
 a=d%365;
 w=a/7;
 d=a%7;
 
 cout << endl << "Years: "<< y 
 << endl << "Weeks: " << w 
 << endl << "Days: " << d;
 
 return 0; 
}

Output:

convert given number of days into years,weeks and days

 

Other Related Search Terms

  1. C Program to convert given number of days into years, weeks and days
  2. C++ program to convert given number of days into years, weeks and days
  3. C and C++ program for check remaining years, weeks and days by giving number of days.

Categories: C Language,C Programs,Computer Science

Tags: ,,

Leave A Reply

Your email address will not be published.

×