Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Tamari Tateshvili

Write a program, which asks You your year, month, and day of birth, and also the current
year, month and day and calculates,
how many days old are you?

#include "stdio.h"

struct month
{
int days;
};

struct year
{
int days;
};

int main()
{
month A[12];
year Y[22];
int birth_y, birth_m, birth_d, cur_y, cur_m, cur_d;

A[0].days = 31; A[1].days = 28; A[2].days = 31;


A[3].days = 30; A[4].days = 31; A[5].days = 30;
A[6].days = 31; A[7].days = 31; A[8].days = 30;
A[9].days = 31; A[10].days = 30; A[11].days = 31;

printf("\n Insert your birth of year: "); scanf(" %d", &birth_y);


birth_y = birth_y-2000;
printf("\n Insert your birth of month's number: "); scanf(" %d", &birth_m);
birth_m --;
printf("\n Insert your birth of day: "); scanf(" %d", &birth_d);
printf("\n Insert current year: "); scanf(" %d", &cur_y);
cur_y = cur_y-2001;
printf("\n Insert current month number: "); scanf(" %d", &cur_m);
cur_m --;
printf("\n Insert current day's number: "); scanf(" %d", &cur_d);
int k = cur_y - birth_y;

for (int x = 0; x < 23; x++)


{
if ((birth_y + 2001) % 4 == 0 && x < k)
{
Y[x].days = 366;
A[1].days = 29;
}
else if (x < k)
{
Y[x].days = 365;
A[1].days = 28;

}
else Y[x].days = 0;

birth_y++;
}

int sum1 = 0, sum2 = 0, sum3 = 0, all = 0;


for (int i = 0; i < cur_m; i++) sum1 = sum1 + A[i].days;
for (int m = birth_m; birth_m < 12; birth_m++) sum2 = sum2 + A[birth_m].days;
for (int b = 0; b<23; b++) sum3 = sum3 + Y[b].days;

all = sum1 + sum2 + sum3 + cur_d - birth_d - 1;

printf("\n You are %d days old \n", all);


}

You might also like