Αυτήν την φόρα έφτιαξα ένα πρόγραμμα σε C που βρείσκει την ηλικία σας... σε ημέρες!
Για την ακρίβεια βρίσκει πόσων ημερών θα είστε στις 12:00 τα μεσάνυχτα
Στην πρώτη ερώτηση θα βάλετε την ημερομηνία γέννησης σας.
Στην δεύτερη την σημερινή ημερομηνία (Αυτό στην επόμενη έκδοση δεν θα χρειάζετε, θα το κάνει αυτόματα...).
Και μετά αυτό θα βγάλει πόσες μέρες ζείτε!
Εδώ είναι ο κώδικας:
- Κώδικας: Επιλογή όλων
#include <stdio.h>
int main (void) {
struct {int day; int month; int year;} born, today;
int born_month_to_days = 0, years_lived_in_days = 0, months_of_this_year_in_days = 0, is_leap, year_checker, counter, age_in_days;
const int months_in_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf ("Birth date (dd/mm/yyyy): ");
scanf ("%d/%d/%d", &born.day, &born.month, &born.year);
printf ("Today date (dd/mm/yyyy): ");
scanf ("%d/%d/%d", &today.day, &today.month, &today.year);
for (year_checker = born.year; year_checker < today.year; year_checker++) {
if ( (year_checker % 4 == 0 && year_checker % 100 != 0) || (year_checker % 400 == 0) ) is_leap = 1;
else is_leap = 0;
if (is_leap == 1) years_lived_in_days += 366;
else years_lived_in_days += 365;
}
for (counter = 1; counter <= born.month; counter++)
born_month_to_days += months_in_days[counter - 1];
for (counter = 1; counter <= today.month; counter++)
months_of_this_year_in_days += months_in_days[counter - 1];
age_in_days = (years_lived_in_days + months_of_this_year_in_days + today.day) - (born_month_to_days + born.day);
if ( (born.year % 4 == 0 && born.year % 100 != 0) || (born.year % 400 == 0) ) is_leap = 1;
else is_leap = 0;
if (born.month > 2 && is_leap == 1) age_in_days--;
if ( (today.year % 4 == 0 && today.year % 100 != 0) || (today.year % 400 == 0) ) is_leap = 1;
else is_leap = 0;
if (today.month < 2 && is_leap == 1) age_in_days--;
printf ("Today you are %d days old.\n", age_in_days);
return 0;
}
Βρείτε πόσων ημερών είστε!




