Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Version 1
- // 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, NewNumber, days,months, years; // variable declaration
- // entering the number of days as an integer
- printf("\n Input an positive integer number = ");
- scanf("%d",&n);
- // n changes over the course of the calculation,
- // so we remember n in the mem_n 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;
- // We take so many years from n and this is our new n
- n = n-years*365;
- // We now reckon how many months are in such a n
- months = n/30;
- // We take so many months from n, and again this is new n
- n = n-months*30;
- // n now represents the number of days remaining
- days = n;
- // display results
- printf("\n %d days is %d years %d months and %d days \n\n",mem_n,years,months,days);
- }
Add Comment
Please, Sign In to add comment