Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- /* declare variables */
- int month, day, year, month_back, day_back, year_back, i;
- /* start loop, set i = 0, continue loop if month/day/year are not 0, increment i after each run */
- for(i = 0 ; month != 0 && year != 0 && day != 0 ; i++) {
- /* take date and store date into variables month/day/year */
- printf("Enter a date mm/dd/yy: ");
- scanf("%2d/%2d/%2d", &month, &day, &year);
- /* if i = 0(first run) make back ups of the original date */
- if (i = 0) {
- month_back = month;
- day_back = day;
- year_back = year;
- }
- /* if this is not the first run (i != 0) */
- else if (i != 0) {
- /* check if the new year entered is less than the previous year entered
- if yes then set the back ups to the current date */
- if (year < year_back) {
- year_back = year;
- day_back = day;
- month_back = month;
- }
- /* if the years are the same*/
- else if (year == year_back) {
- /* check if the new month is before the previously entered month */
- if (month < month_back) {
- year_back = year;
- day_back = day;
- month_back = month;
- }
- /* if the months are equal */
- if (month == month_back) {
- /* check if the day is before the previous day
- if so then set the back ups to the new date*/
- if (day < day_back) {
- year_back = year;
- day_back = day;
- month_back = month;
- }
- /* or leave the back ups in place if the criteria are not met*/
- }
- }
- }
- }
- /* if the loop is finished (0/0/0 is entered) then print the earliest date (whatever is stored in the back up variables */
- printf("\nEarliest: %2d/%2d/%2d", month_back, day_back, year_back);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement