Not understanding logic ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Not understanding logic !

https://code.sololearn.com/cs968l7G5v6V/?ref=app In this program, I want to know why when the years are same and m2 is less than m1 , y don't return -1. I mean m2<m1 So, 12 is added to M2 Then 1 is subtracted from y2 i.e. when y1= y2 (eg. Both are 2020), y2 becomes 2020 - 1 = 2019 Now, y = y2 - y1 => y = 2019 - 2020 = -1 This is my logic but the program is okay (works fine) https://overiq.com/c-examples/c-program-to-calculate-the-difference-of-two-dates-in-years-months-and-days/

8th Dec 2020, 7:14 PM
Kashyap Kumar
Kashyap Kumar - avatar
1 Answer
+ 1
It's always giving some junk no. On inputting same year so it does work fine
8th Jan 2021, 7:18 PM
Nihar Buliya
Nihar Buliya - avatar