Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int d1=-1,d2=33,m1=-1,m2=13,y1=-1,y2=20000;
- while(1)
- {
- char s[11],s1[3]="",s2[3]="",s3[5]="";
- int count=0,day,month,year;
- printf("Enter a date: ");
- scanf("%s",s);
- for(int i=0; s[i]!='\0'; i++)
- {
- if(s[i]=='/')
- {
- count++;
- }
- if(s[i]!='/' && count==0)
- {
- //strncat concatenates(joins) a string s1 with a character which is in s[i] and 1 is the size of character
- strncat(s1,&s[i],1);
- }
- else if(s[i]!='/' && count==1)
- {
- strncat(s2,&s[i],1);
- }
- else if(s[i]!='/' && count==2)
- {
- strncat(s3,&s[i],1);
- }
- }
- //atoi(string) converts string to int
- day=atoi(s1);
- month=atoi(s2);
- year=atoi(s3);
- if(day==0 && month==0 && year==0)
- {
- printf("Highest date: %d/%d/%d\n",d1,m1,y1);
- printf("Lowest date: %d/%d/%d",d2,m2,y2);
- break;
- }
- //checking if the year is highest or not
- if(year>y1)
- {
- y1=year;
- d1=day;
- m1=month;
- }
- else if(y1==year)
- {
- if(month>m1)
- {
- m1=month;
- d1=day;
- }
- else if(month==m1)
- {
- if(day>d1)
- {
- d1=day;
- }
- }
- }
- //check if a year is lowest
- if(year<y2)
- {
- y2=year;
- m2=month;
- d2=day;
- }
- else if(year==y2)
- {
- if(month,m1)
- {
- m2=month;
- d2=day;
- }
- else if(month==m1)
- {
- if(day<d1)
- {
- d1=day;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement