Complete the C program to convert days into years, month and days. (Ignoring leap year and considering 1 month is 30 days)
Answers
Answered by
5
C program to convert number of days to days, weeks, months and years
/**
* C program to convert Numer of Days to
* Year, Month, Week and Days
*/
#include <stdio.h>
int main() {
int inputDays, years, months, weeks, days;
/*
* Take number of days as input from user
*/
printf("Enter number of Days\n");
scanf("%d", &inputDays);
/*
* 1 Year = 365 Days, 1 Month = 30 Days, 1 Week = 7 Days
* To keep things simple, We are not considering Leap years
* and assuming 1 Month = 30 Days
*/
years = inputDays/365;
// Remaining days after year
inputDays = inputDays - years*365;
months = inputDays/30;
// Remaining days after month
inputDays = inputDays - months*30;
weeks = inputDays/7;
// Remaining days after week
inputDays = inputDays - weeks*7;
days = inputDays;
printf("Years : %d\n", years);
printf("Months : %d\n", months);
printf("Weeks : %d\n", weeks);
printf("Days : %d", days);
return 0;
}
OutputEnter number of Days 400 Years : 1 Months : 1 Weeks : 0 Days : 5
/**
* C program to convert Numer of Days to
* Year, Month, Week and Days
*/
#include <stdio.h>
int main() {
int inputDays, years, months, weeks, days;
/*
* Take number of days as input from user
*/
printf("Enter number of Days\n");
scanf("%d", &inputDays);
/*
* 1 Year = 365 Days, 1 Month = 30 Days, 1 Week = 7 Days
* To keep things simple, We are not considering Leap years
* and assuming 1 Month = 30 Days
*/
years = inputDays/365;
// Remaining days after year
inputDays = inputDays - years*365;
months = inputDays/30;
// Remaining days after month
inputDays = inputDays - months*30;
weeks = inputDays/7;
// Remaining days after week
inputDays = inputDays - weeks*7;
days = inputDays;
printf("Years : %d\n", years);
printf("Months : %d\n", months);
printf("Weeks : %d\n", weeks);
printf("Days : %d", days);
return 0;
}
OutputEnter number of Days 400 Years : 1 Months : 1 Weeks : 0 Days : 5
Similar questions