#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>
char MyAge(char*);
using namespace std;
int main()
{
setlocale(LC_ALL,"rus");
char str_result;
char str1[20];
cout << "Введите дату рождения в формате - число/месяц/год" << endl;
cin >> str1;
MyAge(str1);
return 0;
}
char MyAge(char*str1)
char day[3], month[3], year[5];
int age;
int a = 2021;
//char str2[100];
for(int i = 0; i < *str1; i++)
if(str1[i] == '/')
str1[i] = ' ';
istringstream ss(str1);
(ss >> day).get();
(ss >> month).get();
(ss >> year).get();
age = atoi(year);
age = a - age;
ostringstream str2;
str2 << "Лет - " << age << " Месяцев - "<< month << " Дней - " << day;
cout << str2;
Объяснение:
from datetime import date
def calculate_age(born):
today = date.today()
try:
birthday = born.replace(year=today.year)
except ValueError: # raised when birth date is February 29 and the current year is not a leap year
birthday = born.replace(year=today.year, month=born.month+1, day=1)
if birthday > today:
return today.year - born.year - 1
else:
return today.year - born.year
Начало это си а конец питон
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>
char MyAge(char*);
using namespace std;
int main()
{
setlocale(LC_ALL,"rus");
char str_result;
char str1[20];
cout << "Введите дату рождения в формате - число/месяц/год" << endl;
cin >> str1;
MyAge(str1);
return 0;
}
char MyAge(char*str1)
{
char day[3], month[3], year[5];
int age;
int a = 2021;
//char str2[100];
for(int i = 0; i < *str1; i++)
if(str1[i] == '/')
str1[i] = ' ';
istringstream ss(str1);
(ss >> day).get();
(ss >> month).get();
(ss >> year).get();
age = atoi(year);
age = a - age;
ostringstream str2;
str2 << "Лет - " << age << " Месяцев - "<< month << " Дней - " << day;
cout << str2;
}
Объяснение:
from datetime import date
def calculate_age(born):
today = date.today()
try:
birthday = born.replace(year=today.year)
except ValueError: # raised when birth date is February 29 and the current year is not a leap year
birthday = born.replace(year=today.year, month=born.month+1, day=1)
if birthday > today:
return today.year - born.year - 1
else:
return today.year - born.year
Начало это си а конец питон