1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <time.h>
4: #define YEAR_FACTOR 1900
5: #define MONTH_FACTOR 1
6: int main(int argc, char *argv[])
7: {
8: struct tm *tm;
9: time_t ltime, cts;
10: int year = 0, month = 0, date = 0;
11: int age_year = 0, age_month = 0, age_day = 0, age_hrs = 0, age_minut = 0,
12: age_second = 0;
13: printf("Enter your DOB\n");
14: printf("Data(The day you born):");
15: scanf("%d",&date);
16: printf("Month:");
17: scanf("%d",&month);
18: printf("Year:");
19: scanf("%d",&year);
20: //Get current time stamp
21: cts = time(NULL);
22: tm = localtime(&cts);
23: age_year = (tm->tm_year+YEAR_FACTOR) - year;
24: age_month = (tm->tm_mon+MONTH_FACTOR) - month;
25: age_day = tm->tm_mday - date;
26: printf("Year : %d\tMonth : %d\tDay : %d\n",age_year,age_month,
27: age_day);
28: }
RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Search This Blog
Saturday, October 31, 2015
Write a C program to calculate your age.
Labels:
C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment