Advertisement
dmilicev

Year_Month_Day_v2.c

Sep 22nd, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. // Version 2
  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,days,months, years; // variable declaration
  11.  
  12. // entering the number of days as an integer, n
  13.     printf("\n Input an positive integer n = ");
  14.     scanf("%d",&n);
  15.  
  16. // n changes over the course of the calculation,
  17. // so we remember n in the number because we need to print the results at the end.
  18.  
  19.     mem_n=n;
  20.  
  21. // First, we find out how many whole years are contained in n.
  22.  
  23.     years = n/365;
  24.  
  25. // Then we find how many months are contained in the remaining n
  26.  
  27.     months = (n-years*365)/30;
  28.  
  29. // Then we find how many days are contained in the remaining n
  30.  
  31.     days = n - years*365 - months*30;
  32.  
  33.  
  34. // display results
  35.  
  36.     printf("\n %d days is %d years %d months and %d days \n\n",mem_n,years,months,days);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement