Age in Days beeCrowd 1020 URI Solution C, Python alpha codist years days monts converting coding programming input modulus % / mes(es) dia(s) ano(s)
Age in Days
You have to read an integer value. This value is in seconds. All you have to do is convert it to hour:minute: second format.
The formula is:
- Take input.
- Convert the days to years.
- Then subtract the number of days you converted. (days % 365)
- Now convert the remaining to months.
- At last, get the remaining days.
- Print as said.
The solution in C:
#include <stdio.h>
int main() {
int days,months,years;
scanf("%d",&days);
years = days/365;
days = days % 365;
months = days/30;
days = days % 365 % 30;
printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",years,months,days);
return 0;
}
The solution in Python:
days = int(input())
years = days/365;
days = days % 365;
months = days/30;
days = days % 365 % 30;
print("%d ano(s)\n%d mes(es)\n%d dia(s)" % (years,months,days));
COMMENTS