Q:

Write a C program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days

0

Write a C program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days. 

Test Data :
Input no. of days: 2535
Expected Output:
6 Year(s)
11 Month(s)
15 Day(s)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main() {
	int ndays, y, m, d;	
	printf("Input no. of days: ");
	scanf("%d", &ndays);
	y = (int) ndays/365;
	ndays = ndays-(365*y);	
	m = (int)ndays/30;
	d = (int)ndays-(m*30);
	printf(" %d Year(s) \n %d Month(s) \n %d Day(s)", y, m, d);
	return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Basic Declarations and Expressions exercises

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program that accepts 4 integers p, q, r,... >>
<< Write a C program to convert a given integer (in s...