Tuesday, 11 February 2014

// // Leave a Comment

Program for changing background color

Here is a program to change the color of the background.In this the choices will be taken from the user and display the respective output.
In this program for making choice i use the switch case.



#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
int main(void)
{
    int  i,Graphdriver = DETECT,Graphmode, Errorcode,n;        
    initgraph( &Graphdriver, &Graphmode, "C:\\TURBOC3\\BGI" );

    Errorcode = graphresult();
    if( Errorcode != grOk )
    {
        printf(" Graphics System Error: %s\n", grapherrormsg( Errorcode ) );
        exit( 1 );
    }

    cleardevice();
    
for(i=0;i<13;i++)
      {
    cleardevice();
    printf("which color is set as background color:\n");
    printf("1.Blue\t\t2.Red\t\t3.Graan\t\t4.Cyan\t\t5.Brown\t\t\n6.LightGray\t7.DarkGray\t");
    printf("8.LightGreen\t9.LightBlue\t10.LightCyan\t\n11.LightRed\t12.LightMagenta\t13.Yellow");
    printf("\t14.Magenta\t15.exit\n");
    printf("\nenter choice:-");
    scanf("%d",&n);
    switch(n)
    {
        case 1:setbkcolor(BLUE);
            break;
        case 2:setbkcolor(RED);
            break;
        case 3:setbkcolor(GREEN);
            break;
        case 4:setbkcolor(CYAN);
            break;
        case 5:setbkcolor(BROWN);
            break;
        case 6:setbkcolor(LIGHTGRAY);
            break;
        case 7:setbkcolor(DARKGRAY);
            break;
        case 8:setbkcolor(LIGHTGREEN);
            break;
        case 9:setbkcolor(LIGHTBLUE);
            break;
        case 10:setbkcolor(LIGHTCYAN);
            break;
        case 11:setbkcolor(LIGHTRED);
            break;
        case 12:setbkcolor(LIGHTMAGENTA);
            break;
        case 13:setbkcolor(YELLOW);
            break;
        case 14:setbkcolor(MAGENTA);
            break;
        case 15:printf("exit....");
            exit(0);
            break;
        default:printf("invalid choice......");
            break;
    }

      }
    cleardevice();
    getch();
    return 1;
}

O/P DEMO:-

STEP_1


STEP_2



0 comments:

Post a Comment