czwartek, 4 lipca 2019

Days and months 2019 (C-gcc)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char **argv)
{
char months[12][20];
int months_values[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int day_months;
int sum[12];
char days[7][20];
int day;
char which_Day[20];
char which_Monat[20];
int i,j,s;
srand(time(NULL));
s=0;
for(i=0;i<12;i++)
{
s+=months_values[i];
sum[i]=s;

}
strcpy(months[0],"January");
strcpy(months[1],"February");
strcpy(months[2],"March");
strcpy(months[3],"April");
strcpy(months[4],"May");
strcpy(months[5],"June");
strcpy(months[6],"July");
strcpy(months[7],"August");
strcpy(months[8],"September");
strcpy(months[9],"October");
strcpy(months[10],"November");
strcpy(months[11],"December");
strcpy(days[6],"Monday");
strcpy(days[0],"Tuesday");
strcpy(days[1],"Wednesday");
strcpy(days[2],"Thursday");
strcpy(days[3],"Friday");
strcpy(days[4],"Saturday");
strcpy(days[5],"Sunday"); 
day=rand()%365+1;
i=1;
j=0;
do
{


if(j==7)
j=0;
++i;
++j;

}while(i<day);
strcpy(which_Day,days[j]);
if(day<sum[0]+1)
{
strcpy(which_Monat,months[0]);
day_months=day;
}
if(day>sum[0] && day<sum[1]+1)
{
strcpy(which_Monat,months[1]);
day_months=day-sum[0];
}
if(day>sum[1] && day<sum[2]+1)
{
strcpy(which_Monat,months[2]);
day_months=day-sum[1];
}
if(day>sum[2] && day<sum[3]+1)
{
strcpy(which_Monat,months[3]);
day_months=day-sum[2];
}
if(day>sum[3] && day<sum[4]+1)
    {
strcpy(which_Monat,months[4]);
day_months=day-sum[3];
}
if(day>sum[4] && day<sum[5]+1)
{
strcpy(which_Monat,months[5]);
day_months=day-sum[4];
}
if(day>sum[5] && day<sum[6]+1)
{
strcpy(which_Monat,months[6]);
day_months=day-sum[5];
}
if(day>sum[6] && day<sum[7]+1)
{
strcpy(which_Monat,months[7]);
day_months=day-sum[6];
}
if(day>sum[7] && day<sum[8]+1)
{
strcpy(which_Monat,months[8]);
day_months=day-sum[7];
}
if(day>sum[8] && day<sum[9]+1)
{
strcpy(which_Monat,months[9]);
day_months=day-sum[8];
}
if(day>sum[9] && day<sum[10]+1)
{
strcpy(which_Monat,months[10]);
day_months=day-sum[9];
}
if(day>sum[10] && day<sum[11]+1)
{
strcpy(which_Monat,months[11]);
day_months=day-sum[10];
}  
 
printf("Value =  %d\n",day);
printf("Month = %s\n",which_Monat);
printf("Day = %d\n",day_months);
printf("Day of the week = %s\n",which_Day);



return 0;
}

Brak komentarzy:

Prześlij komentarz