Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- int main() {
- size_t size = 52;
- char date1[12], date2[12], *p;
- p = (char*)malloc(size * sizeof(char));
- getline(&p, &size, stdin);
- p[strlen(p)-1] = '.';
- scanf("%s%s", date1, date2);
- int day1 = (date1[0] - '0') * 10 + (date1[1] - '0');
- int day2 = (date2[0] - '0') * 10 + (date2[1] - '0');
- int month1 = (date1[3] - '0') * 10 + (date1[4] - '0');
- int month2 = (date2[3] - '0') * 10 + (date2[4] - '0');
- int year1 = (date1[6] - '0') * 1000 + (date1[7] - '0') * 100 + (date1[8] - '0') * 10 + (date1[9] - '0');
- int year2 = (date2[6] - '0') * 1000 + (date2[7] - '0') * 100 + (date2[8] - '0') * 10 + (date2[9] - '0');
- int anos = year1 - year2 - 1 + ((month1 == month2 && day1 >= day2) || month1 > month2);
- if(day1 == day2 && month1 == month2) printf("Feliz aniversario!\n");
- printf("Voce tem %d anos %s\n", anos, p);
- }
Advertisement
Add Comment
Please, Sign In to add comment