Advertisement
phoenix79194

Datumscheck

Mar 1st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. //Datumscheck
  2.  
  3. #include <stdio.h>
  4.  
  5. void main()
  6. {
  7.    
  8.     system("chcp 1252");
  9.     system("cls");
  10.        
  11.    int t,m,j;
  12.    int monatstage[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  13.    int check = 0;
  14.  
  15.    printf("Bitte geben Sie ein Datum im Format tt.mm.jjjj ein:");
  16.    scanf("%i.%i.%i",&t,&m,&j);
  17.  
  18.    // Prüfung Schaltjahr
  19.    if(j % 400 == 0 || (j % 100 != 0 && j % 4 == 0))
  20.     monatstage[1]=29;
  21.  
  22.    // Prüfung Tage im Monat
  23.    if (m < 13)
  24.    {
  25.       if( t <= monatstage[m-1] )
  26.         check=1;
  27.    }
  28.  
  29.    if (check==1)
  30.       printf("Es ist ein gültiges Datum!\n");
  31.    else
  32.       printf("Es ist kein gültiges Datum!\n");
  33.      
  34. system("pause");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement