Tuesday, 22 April 2014

How to Use Switch Statement in C

#Jai_Hind Friends I am DeepakSaini  i m here to explain something about switch statement of C .
Love to :- My Father,My Mother,Sumit Dagar ,DeadManINDIA,Govind Singh <3 <3

Steups:- 

Steup1:- First of all we are explain how to declare switch in a program.
              
                    {
                      int a = 1;

                     switch(a)
                   {
                      case 1:
                     do this ;
                     break;
                      

                        case 2:
                      do this ;
                       break;
                     
                       default:
                       do this;
                        break;

                    }

    This is the way of declare the switch statement .


How it works 
1 check the case 1st if 1st match then break the and print the do this in my case which i define in 1st casse 

2 Then check 2nd and then check all cases which we are declare in the switch and at last we are define the default if none case match then print that do this . I explain this in my little program.


Here is the program.

#include<stdio.h>
int main()
{
int a;
printf (" enter the no 1 or 2 = \n");
scanf("%d",&a);

switch(a)
{
case 1:
printf("I am Deepak Saini\n");
break;

case 2:

printf("I love my MOM and DAD more then GOD\n");

break;

default:
printf("Happy go Lucky\n");

}

return 0;
}


We are using break statement to break if our case is matched if we are not using this then our program give all cases do this on screen. so we are using the break statement.


Thats it :) 
                                                   Jai Hind 
                                                   Jai Bharat 
                                    Ram Ram Dosto 



0 comments:

Post a Comment