Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- 2 #include<math.h>
- 3
- 4 int tage[12]={0,31,59,90,120,151,181,212,243,273,304,334};
- 5
- 6 int schaltjahr(int jahr)
- 7 {
- 8 if((jahr%4==0 && jahr%100!=0) || jahr%400==0){
- 9
- 10 return 1;
- 11 else{
- 12
- 13
- 14
- 15 return 0;
- 16 }
- 17 }
- 18 int tag_im_jahr(int t, int m, int jahr)
- 19 {
- 20 int t_i_j=0;
- 21
- 22 if(schaltjahr(jahr)==1 && m>2)
- 23 t_i_j=tage[--m]+ ++t;
- 24 else
- 25 t_i_j=tage[--m]+ t;
- 26
- 27 return t_i_j;
- 28 }
- 29 int main()
- 30 {
- 31 int t=0, m=0, jahr=0, max=0;
- 32 printf("\nGeben Sie bitte ein Datum ein:");
- 33 scanf("%d.%d.%4d", &t, &m, &jahr);
- 34 switch(m)
- 35 {
- 36 case 1:
- 37 case 3:
- 38 case 5:
- 39 case 8:
- 40 case 10:
- 41 case 12:max=31;break;
- 42 case 4:
- 43 case 6:
- 44 case 9:
- 45 case 11:max=30;break;
- 46 case 2:
- 47 if (schaltjahr(jahr)==0)
- 48 {
- 49 max=28;break;
- 50 }
- 51 else
- 52 {
- 53 max=29;break;
- 54 }
- 55 }
- 56 if(m<=13 ||t > max || jahr <=1538 || m < 1 || t < 1)
- 57 {
- 58 printf("\nDie Eingabe ist fehlerhaft");
- 59 return 1;
- 60 }
- 61 printf("%2d.%2d.%4d", t, m, jahr;
- 62 printf("%d Tag im Jahr", tag_im_jahr(t,m,jahr));
Add Comment
Please, Sign In to add comment