Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. bool CheckBisestile(int Y);
  6. bool CheckData(int Y, int M, int D);
  7.  
  8. int main()
  9. {
  10.     int Y, M, D;
  11.     do
  12.     {
  13.         printf("Inserisci l'anno.\n");
  14.         scanf("%d", &Y);
  15.         printf("Inserisci il mese.\n");
  16.         scanf("%d", &M);
  17.         printf("Inserisci il giorno.\n");
  18.         scanf("%d", &D);
  19.     }
  20.     while(CheckData(Y, M, D) == false);
  21.     return 0;
  22. }
  23.  
  24. bool CheckData(int Y, int M, int D)
  25. {
  26.     int DOM;
  27.     if(Y < 0 || Y > 3000) return false;
  28.     switch(M)
  29.     {
  30.         case 1-3-5-7-8-10-12: DOM = 31;
  31.         case 4-6-9-11: DOM = 30;
  32.         case 2:
  33.         {
  34.             if(CheckBisestile(Y) == true) DOM = 29;
  35.             else DOM = 28;
  36.         }
  37.         default: return false;
  38.     }
  39.     if(D < 1 || D > DOM) return false;
  40.     printf("La data รจ corretta!\n");
  41.     return true;
  42. }
  43.  
  44. bool CheckBisestile(int Y)
  45. {
  46.     if ((Y % 4) == 0 && (Y % 100) != 0 || (Y % 400) == 0) return true;
  47.     return false;  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement