Switch in C

SWITCH IN .C

switch keyword is use to choose any one option  

[syntax]

switch(variable)

{


}

-----------------------------------------

swtch program run screen

------------------------------------------


source code 

#################

#include<stdio.h>
#include<conio.h>

// code by [UB] //

main()
{

    int choice,a,b,s;
    clrscr();
    while(1)
    {

        printf("\n###################");
        printf("\n1. add numbers");
        printf("\n2. odd or even");
        printf("\n3.  multiply  ");
        printf("\n4. devide     ");
        printf("\n5. About devloper");
        printf("\n6.  Exit"     );
        printf("\n*******************");
        printf("\nenter your choice= ");
        scanf("%d",&choice);

        switch(choice)
        {
        case 1:

            printf("\n1.enter two numbers= ");
            scanf("\n%d %d",&a,&b);
            s=a+b;
            printf("\nThe sum is=[ %d ]",s);

            break;

        case 2:
            printf("\n2.enter a number= ");
            scanf("%d",&a);
            if(a%2==0)

                printf("\n** Even number **");

            else
                printf("\n** Odd number **");

            break;

        case 3:
            printf("\n3.Enter two number= ");
            scanf("%d %d",&a,&b);
            s=a*b;
            printf("sum is [ %d ]",s);

            break;
        case 4:
            printf("\n4.enter two numbers= ");
            scanf("%d %d",&a,&b);
            s=a%b;
            printf("ANS=[ %d ] ",s);
            break;

        case 5:
            printf("[this program is #code# by $ upjeet baswan $ ]");
            break;

        case 6:
            exit(0);

        default:
            printf("**{invaled choice}**");

        }

    }

    getch();

}

######################### 

ALL RIGHTS GOES TO *[UB CODES]*

\--------------------------------------------------/

Popular posts from this blog

[2D] ARRAY

2D [STRING] IN C