dmilicev

Year_Month_Day_v1.c

Sep 22nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. // Version 1
  2. // Program that accepts days as integer
  3. // and display total numbers of years, month and days.
  4. // The condition is that the year is 365 days and the month is 30 days.
  5.  
  6. #include<stdio.h>
  7.  
  8. void main(void)
  9. {
  10.     int n, mem_n, NewNumber, days,months, years;    // variable declaration
  11.  
  12. // entering the number of days as an integer
  13.     printf("\n Input an positive integer number = ");
  14.     scanf("%d",&n);
  15.  
  16. // n changes over the course of the calculation,
  17. // so we remember n in the mem_n because we need to print the results at the end.
  18.     mem_n = n;
  19.  
  20. // First, we find out how many whole years are contained in n.
  21.     years = n/365;
  22.  
  23. // We take so many years from n and this is our new n
  24.     n = n-years*365;
  25.  
  26. // We now reckon how many months are in such a n
  27.     months = n/30;
  28.  
  29. // We take so many months from n, and again this is new n
  30.     n = n-months*30;
  31.  
  32. // n now represents the number of days remaining
  33.     days = n;
  34.  
  35. // display results
  36.     printf("\n %d days is %d years %d months and %d days \n\n",mem_n,years,months,days);
  37. }
Add Comment
Please, Sign In to add comment