Micours

mail@pastecode.io avatar
unknown
pascal
2 years ago
1.5 kB
2
Indexable
Never
Program tp4;
Type
  dt = Record
    jour : Integer;
    mois : Integer;
    annee : Integer;
  End;
Var
  date : dt ;
  y,x,i,s : Integer;
Begin
  x := 0;
  s := 0;
  For y:=1 To 2 Do
    //2 dates
    Begin
      Writeln('Entrez un date : jour mois année ');
      Readln( date.jour, date.mois, date.annee);
      While ((date.jour<=0) Or (date.jour>31) Or (date.mois>12) Or (date.annee<=0) ) Do
        //verfication loop
        Begin
          Writeln('Entrez une  date valide : jour mois année ');
          Readln(date.jour ,date.mois ,date.annee);
        End;
      s := date.jour;
      For i:= 1 To date.mois-1 Do
        Case i Of
          3,5,7,8,10,12,1 : s := s+31;
          4,6,9,11 : s := s +30;
          2 : If ((date.annee Mod 100)=0) And ((date.annee Mod 400) = 0 ) Then //convert months to days
                s := s+29
              Else If date.annee Mod 4 = 0 Then
                     s := s+29
              Else s := s+28;
        End;                                                                                                                            //Convert years to days
      For i:= 1 To date.annee  Do

            If (i Mod 100 = 0) And (i Mod 400 = 0) Then s := s+366
            Else If (i Mod 4 =0) Then s := s+366
            Else s := s+365;
                    x:=s-x ;

    End;


  If (x)<=0 Then
    Writeln('la difference est :',-x)
  Else Writeln('la difference est :',x);
  Readln;
End.