mramine364

Previous Day

Aug 26th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool isLeap(int y){
  6.     return y%400==0 || y%4==0 && y%100!=0;
  7. }
  8.  
  9. void previousDay(int day, int month, int year)
  10. {
  11.     int ms[]={31,28,31,30,31,30,31,31,30,31,30,31};
  12.     if( isLeap(year) )
  13.         ms[1]=29;
  14.    
  15.     if( day==1 ){
  16.         if( month==1 ){
  17.             cout << 31 << "/"<<12<<"/"<<year-1<<endl;
  18.         }else{
  19.             cout << ms[month-2] << "/"<<month-1<<"/"<<year<<endl;
  20.         }
  21.     }else{
  22.         cout << day-1 << "/"<<month<<"/"<<year<<endl;
  23.     }
  24. }
  25. int main()
  26. {
  27.    previousDay(1,3,2017);
  28.    
  29.    return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment