SHARE
TWEET

Untitled

a guest Oct 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Se dau datele de nastere a 2 studenti in formatul luna/zi/an.
  2. a. Cine este mai in varsta?
  3. b. Cu cati ani/luni/zile este mai in varsta?
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. void findAge(int current_date,int current_month,
  11.              int current_year, int birth_date,
  12.              int birth_month, int birth_year)
  13. {
  14.     int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  15.  
  16.     if(birth_date > current_date){
  17.         current_date = current_date + month[birth_month - 1];
  18.         current_month = current_month - 1;
  19.     }
  20.     if(birth_month > current_month){
  21.         current_year = current_year - 1;
  22.         current_month = current_month + 12;
  23.     }
  24.     int calculated_date = current_date - birth_date;
  25.     int calculated_month = current_month - birth_month;
  26.     int calculated_year = current_year - birth_year;
  27.  
  28.     printf("\nYour age:\n\nYears: %d \nMonths: %d \nDays:"
  29.            "%d\n", calculated_year, calculated_month, calculated_date);
  30. }
  31.  
  32.     int main()
  33.     {
  34.         time_t rawtime;
  35.         struct tm *info;
  36.         time( &rawtime );
  37.         info = localtime( &rawtime );
  38.         //printf("Current local time and date: %s", asctime(info));
  39.  
  40.         int birth_date, birth_month, birth_year, age_difference_years, age_difference_months, age_difference_days;
  41.         int *current_date, *current_month, *current_year;
  42.         current_date = info -> tm_mday;
  43.         current_month = info -> tm_mon + 1;
  44.         current_year = info -> tm_year + 1900;
  45.  
  46.  
  47.         printf("\nPerson 1. \n");
  48.         printf("\nWhat day were you born?\n");
  49.         printf("Date = ");scanf("%d", &birth_date);
  50.         printf("What month were you born?\n");
  51.         printf("Month = ");scanf("%d", &birth_month);
  52.         printf("What year were you born?\n");
  53.         printf("Year = " );scanf("%d", &birth_year);
  54.  
  55.         int birth_date1 = birth_date;
  56.         int birth_month1 = birth_month;
  57.         int birth_year1 = birth_year;
  58.  
  59.  
  60.         findAge(current_date,current_month, current_year,
  61.                 birth_date, birth_month, birth_year);
  62.  
  63.  
  64.         printf("\n\nPerson 2. \n");
  65.         printf("\nWhat day were you born?\n");
  66.         printf("Date = ");scanf("%d", &birth_date);
  67.         printf("What month were you born?\n");
  68.         printf("Month = ");scanf("%d", &birth_month);
  69.         printf("What year were you born?\n");
  70.         printf("Year = " );scanf("%d", &birth_year);
  71.  
  72.  
  73.         findAge(current_date,current_month, current_year,
  74.                 birth_date, birth_month, birth_year);
  75.  
  76.  
  77.         if(birth_year > birth_year1)
  78.             age_difference_years = birth_year - birth_year1;
  79.         else
  80.             age_difference_years = birth_year1 - birth_year;
  81.         if(birth_month > birth_month1)
  82.             age_difference_months = birth_month - birth_month1;
  83.         else
  84.             age_difference_months = birth_month1 - birth_month;
  85.         if(birth_date > birth_date1)
  86.             age_difference_days = birth_date - birth_date1;
  87.         else
  88.             age_difference_days = birth_date1 - birth_date;
  89.  
  90.  
  91.         printf("\nThe difference between your ages is: \n\nYears: %d \nMonths: %d\nDays: %d\n",
  92.                             age_difference_years, age_difference_months, age_difference_days);
  93.  
  94.  
  95.         if(birth_year1 == birth_year )
  96.             if(birth_month1 == birth_month)
  97.                 if(birth_date1 == birth_date)
  98.                     printf("\nBoth people are the same age.");
  99.                 else if(birth_date1 > birth_date)
  100.                     printf("\nPerson 2 is older.");
  101.                 else
  102.                     printf("\nPerson 1 is older.");
  103.             else if(birth_month1 > birth_month)
  104.                     printf("\nPerson 2 is older.");
  105.                 else
  106.                     printf("\nPerson 1 is older.");
  107.         else if(birth_year1 > birth_year)
  108.                     printf("\nPerson 2 is older.");
  109.                 else
  110.                     printf("\nPerson 1 is older.");
  111.         printf("\n");
  112.         return 0;
  113.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top