Thursday, 28 January 2016

Solution of URI 1052 :: Month


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    if(x==1)
        printf("January\n");
    else if(x==2)
        printf("February\n");
    else if(x==3)
        printf("March\n");
    else if(x==4)
        printf("April\n");
    else if(x==5)
        printf("May\n");
    else if(x==6)
        printf("June\n");
    else if(x==7)
        printf("July\n");
    else if(x==8)
        printf("August\n");
    else if(x==9)
        printf("September\n");
    else if(x==10)
        printf("October\n");
    else if(x==11)
        printf("November\n");
    else if(x==12)
        printf("December\n");
    return 0;
}

3 comments:

  1. #include

    int main()
    {
    int m;
    scanf("%d", &m);

    if(m==1) {
    printf("January\n");
    }

    else if(m==2) {
    printf("February\n");
    }
    else if(m==3) {
    printf("March\n");
    }

    else if(m==4) {
    printf("April\n");
    }
    else if(m==5) {
    printf("May\n");
    }
    else if(m==6) {
    printf("June\n");
    }
    else if(m==7) {
    printf("July\n");
    }
    else if(m==8) {
    printf("August\n");
    }
    else if(m==9) {
    printf("September\n");
    }
    else if(m==10) {
    printf("October\n");
    }

    else if(m==11) {
    printf("Nomvember\n");
    }

    else if(m==12) {
    printf("December\n");
    }

    return 0;
    }

    ReplyDelete
  2. can you write this solution using array

    ReplyDelete
  3. #include
    using namespace std;
    int main()
    {
    int n;
    cin>>n;
    if (n==1){
    cout<<"January"<<endl;
    }
    else if (n==2){
    cout<<"February"<<endl;
    }
    else if (n==3){
    cout<<"March"<<endl;
    }
    else if (n==4){
    cout<<"April"<<endl;
    }
    else if (n==5){
    cout<<"May"<<endl;
    }
    else if (n==6){
    cout<<"June"<<endl;
    }
    else if (n==7){
    cout<<"July"<<endl;
    }
    else if (n==8){
    cout<<"August"<<endl;
    }
    else if (n==9){
    cout<<"September"<<endl;
    }
    else if (n==10){
    cout<<"October"<<endl;
    }
    else if (n==11){
    cout<<"November"<<endl;
    }
    else {
    cout<<"December"<<endl;
    }
    return 0;
    }

    ReplyDelete

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