URI ONLINE JUDGE SOLUTION 1020 - Age in Days
Problem
Solution
#include<stdio.h>
int main()
{
int x,a[3];
scanf("%d",&x);
a[0]=x/365;
x=x%365;
a[1]=x/30;
a[2]=x%30;
printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",a[0],a[1],a[2]);
return 0;
}
Read an integer value corresponding to a person's age (in days) and
print it in years, months and days, followed by its respective message
“ano(s)”, “mes(es)”, “dia(s)”.
Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month. In the cases of test there will never a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for the purpose of testing simple mathematical reasoning.
Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month. In the cases of test there will never a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for the purpose of testing simple mathematical reasoning.
Input
The input file contains 1 integer value.
Output
Solution
#include<stdio.h>
int main()
{
int x,a[3];
scanf("%d",&x);
a[0]=x/365;
x=x%365;
a[1]=x/30;
a[2]=x%30;
printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",a[0],a[1],a[2]);
return 0;
}
Comments
Post a Comment