Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Version 2
- // Program that accepts days as integer
- // and display total numbers of years, month and days.
- // The condition is that the year is 365 days and the month is 30 days.
- #include<stdio.h>
- void main(void)
- {
- int n,mem_n,days,months, years; // variable declaration
- // entering the number of days as an integer, n
- printf("\n Input an positive integer n = ");
- scanf("%d",&n);
- // n changes over the course of the calculation,
- // so we remember n in the number because we need to print the results at the end.
- mem_n=n;
- // First, we find out how many whole years are contained in n.
- years = n/365;
- // Then we find how many months are contained in the remaining n
- months = (n-years*365)/30;
- // Then we find how many days are contained in the remaining n
- days = n - years*365 - months*30;
- // display results
- printf("\n %d days is %d years %d months and %d days \n\n",mem_n,years,months,days);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement