Canna

Sunday, 23 September 2018

Seasoners

Problem Description

The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:

Season First day
Summer March 20
Spring June 21
Fall September 22
Winter December 21 

Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer. 

Then your program should display the season associated with the date that was entered. 

Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capital

  • Test Case 1

    Input (stdin)
    Sep
    
    22
    
    
    Expected Output
    Fall
  • Test Case 2

    Input (stdin)
    Mar
    
    20
    
    
    Expected Output
    Summer
  • Program
  • #include <stdio.h>
    #include<string.h>
    
    int main()
    {
      char a[10];
      int n;
      scanf("%s %d",a,&n);
     if(strcmp(a,"Mar") ==0)
        printf("Summer");
      else if(strcmp(a,"Jun") ==0)
        printf("Spring"); 
      else if(strcmp(a,"Sep") ==0)
        printf("Fall"); 
      else if(strcmp(a,"Dec") ==0)
        printf("Winter");
      return 0;
    
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.