Switch , case statement

//This is the basic switch case statement..

 #include <stdio.h>


int main()

{ char grade ;

printf("Enter your grade\n");

scanf("%c", & grade);


switch(grade){

    case'a':

    printf("you got  the grade A\n All the best\n");

    break;

    case'b':

    printf("you got the grade B\n All the best\n");

    break;

    

    default:

    printf("unknown grade entered\n");

}

//Using range in case value


 #include <stdio.h>




int main()


{ int i ;


printf("Enter your marks  Obtain in class test of 15 marks \n");


scanf("%d", & i);




switch(i){


    case 1 : 

    case 2 :

    case 3 :

    case 4 :

    case 5 :

    case 6 :

    case 7 :

    case 8 :

    case 9 :

    case 10 :


    printf("work hard \n All the best\n");


    break;


    case 11:

    case 12:

    case 13:

    case 14:

    case 15:


    printf("you got the grade A\n All the best\n");


    break;


    


    default:


    printf("unknown grade entered\n");


}


    return 0;

}


//This is simple way but for particular compiler

#include <stdio.h>




int main()


{ int i ;


printf("Enter your marks  Obtain in class test of 15 marks \n");


scanf("%d", & i);




switch(i){


    case 1 ... 10 : 

    


    printf("work hard \n All the best\n");


    break;


    case 11 ... 15 :



    printf("you got the grade A\n All the best\n");


    break;


    


    default:


    printf("unknown grade entered\n");


}


    return 0;

}


Comments

Post a Comment

Popular posts from this blog

Factors : using C

Cross shaped pattern

Factorial ! calculation