वर्तमान तारीख और जन्म तारीख दी गई है, कार्य व्यक्ति की वर्तमान उम्र निकालना है।
उदाहरण
इनपुट: वर्तमान तारीख = 21/9/2019, जन्म तारीख = 25/9/1996 आउटपुट: Present Age Years: 22 Months: 11 Days: 26
दृष्टिकोण
- वर्तमान और जन्म तारीख इनपुट लें।
- यदि वर्तमान महीना जन्म महीने से कम है, तो वर्तमान वर्ष पूरा नहीं हुआ मानकर 12 जोड़ें और वर्ष घटाएं।
- यदि वर्तमान दिन जन्म दिन से कम है, तो उस महीने के दिनों की संख्या जोड़ें और महीना घटाएं।
- अंत में दिन, महीना, वर्ष घटाकर उम्र निकालें।
एल्गोरिदम
START
फंक्शन age(present_date, present_month, present_year, birth_date, birth_month, birth_year)
month[] = {31,28,31,30,31,30,31,31,30,31,30,31}
यदि birth_date > present_date तो
present_date += month[birth_month - 1]
present_month--
यदि birth_month > present_month तो
present_year--
present_month += 12
final_date = present_date - birth_date
final_month = present_month - birth_month
final_year = present_year - birth_year
प्रिंट करें
मुख्य फंक्शन
तारीखें सेट करें
age() कॉल करें
STOP
C कोड उदाहरण
#include <stdio.h>
#include <stdlib.h>
void age(int present_date, int present_month, int present_year,
int birth_date, int birth_month, int birth_year) {
int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
if(birth_date > present_date) {
present_date += month[birth_month - 1];
present_month--;
}
if(birth_month > present_month) {
present_year--;
present_month += 12;
}
int final_date = present_date - birth_date;
int final_month = present_month - birth_month;
int final_year = present_year - birth_year;
printf("Present Age Years: %d Months: %d Days: %d", final_year, final_month, final_date);
}
int main() {
int present_date = 21, present_month = 9, present_year = 2019;
int birth_date = 25, birth_month = 9, birth_year = 1996;
age(present_date, present_month, present_year, birth_date, birth_month, birth_year);
return 0;
}
आउटपुट
Present Age Years: 22 Months: 11 Days: 26