Posts in Category: General

Dynamic Memmory Allocation

malloc()

             The malloc()  function dynamically allocates memory when required. This function allocates ‘size’ byte of memory and returns a pointer to the first byte or NULL if there is some kind of error.The storage is not initialized.

For example:
               int *ptr = malloc(sizeof(int) * 10);      // allocates 10 ints!

                 If it is unable to find the requested amount of memory, malloc() function returns NULL. So you should really check the result for errors:

int *ptr = malloc(sizeof(int) * 5000);
if (ptr == NULL)
       {
       printf(” Out of memory!\n”);
       exit(1);
       }

                 There are only two ways to get allocated memory back. They are exit from the program and calling free() to free function. If your program runs a while and keeps malloc()ing and never free()ing when it should, it is said to “leak” memory. Make sure to avoid memory leaks! free() that memory when you are done with it!

The following example illustrates the use of  malloc() function.

Home

Union

 Union is a data type with two or more member similar to structure but in this case all the members share a common memory location. The size of the union corresponds to the length of the largest member. Since the member share a common location they have the same starting address.

                    The real purpose of unions is to prevent memory fragmentation by arranging for a standard size for data in the memory. By having a standard data size we can guarantee that any hole left when dynamically allocated memory is freed will always be reusable by another instance of the same type of union. This is a natural strategy in system programming where many instances of different kinds of variables with a related purpose and stored dynamically.

                          A union is declared in the same way as a structure.The syntax of union declaration is
union union_name
         {
          type element 1;
          type element 2;
          ……………..
          type element n;
         };
     This declares a type template. Variables are then declared as:
                           union union_name x,y,z;

                             For example, the following code declares a union data type called Student and a union variable called stud:
union student
             {
             int rollno;
             float totalmark;
             };
union student stud;

                              It is possible to combine the declaration of union combination with that of the union variables, as shown below.
union union_name
           {
           type element 1;
           type element 2;
           ……………..
           type element n;
           }var1,var2,…,varn;       

                               The following single declaration is equivalent to the two declaration presented in the previous example.
union student
          {
           int rollno;
           float totalmark;
          }x,y,z;

Exercise: Compare structure and Union

Structure:

Union:

Home

Return statement

  • A function may or may not return a value. A return statement returns a value to the calling function and assigns to the variable in the left side of the calling function.
  • If a function does not return a value, the return type in the function definition and declaration is specified as void.

Example :

123456789101112131415161718192021

222324252627282930313233

3435363738394041424344454647484950515253

54555657585960616263646

5666768697071727374757677787980818

2838485868788899091929394959697

9899100101102103104105106107108109110111112

#include <stdio.h>  #include <conio.h>  void function1();  void function2();  int function3();  int function4();  int main() 

Home

Graphics

Web page Under construction!

The following functions compose the Borland Graphics Interface and are usually available for 16 bit DOS applications. Use them to create onscreen graphics with text. They are defined in graphics.h.

     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 getch();
 closegraph();      /* closes down the graphics system */
 return 0;
}
     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)  
    { 
    printf("Graphics error occurred");
    printf("Press any key to halt:");
    getch();     /* wait for a key */
    exit(1);
    }
     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)  
    { 
    printf("Graphics error occurred");
    printf("Press any key to halt:");
    getch(); 
    exit(1); 
    }
 outtext("Welcome to Borland Graphics Interface");       
/* output the message */
 getch();
 closegraph();
 return 0;
}





     
//outtextxy
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)   
    { 
    printf("Graphics error occurred");
    printf("Press any key to halt:");
    getch();
    exit(1); 
    }
 outtextxy(175,250,"Welcome to Borland Graphics Interface");
 getch();
 closegraph();
 return 0;
}
     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//outtextxy
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
    {
    printf("Graphics error occurred");
    printf("Press any key to halt:");
    getch();
    exit(1);
    }
 setbkcolor(BLUE);
 outtextxy(175,250,"Welcome to Borland Graphics Interface");
 getch();
 closegraph();
 return 0;
}
     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error,maximumcolor;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
    { 
    printf("Graphics error occurred");
    printf("Press any key to halt:");
    getch();
    exit(1); 
    }
 maximumcolor = getmaxcolor();
 for (i=0; i<=maximumcolor;i++)
   {
   setbkcolor(i);    
   outtextxy(175,250,"Welcome to Borland Graphics Interface");   
   outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com"); 
   getch();
   }
 getch();
 closegraph();
 return 0;
}
     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error,maximumcolor;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 maximumcolor = getmaxcolor();
 for (i=0; i<=maximumcolor;i++)
 {
 setbkcolor(i); 
 sprintf(message, "Background color: %d",i); /* create a message string */
 outtextxy(250, 240,message); 
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com");
 getch();
 }
 getch();
 closegraph();
 return 0;
}
     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error,maximumcolor;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 maximumcolor = getmaxcolor();
 for (i=0; i<=maximumcolor;i++)
 {
 cleardevice(); /* clear the screen */
 setbkcolor(i); 
 sprintf(message, "Background color: %d",i);
 outtextxy(250, 240,message); 
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com"); 
 getch();
 }
 getch();
 closegraph();
 return 0;
}
     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error,maximumcolor;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 setbkcolor(BLUE);
 maximumcolor = getmaxcolor();
 for (i=0; i<=maximumcolor;i++)
 {
 cleardevice(); 
 setcolor(i); 
 sprintf(message, "Graphics color: %d",i);
 outtextxy(250, 240,message); 
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com");
 getch();
 }
 getch();
 closegraph();
 return 0;
}
     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,j=0,error,maximumcolor;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for (i=1; i<11; i++)
 {
 /* select the text style, direction, and size */
 settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
 sprintf(message, "Size: %d", i);
 outtextxy(1,j, message);
 /* advance to the next text line */
 j += textheight(message);
 }
 getch();
 closegraph();
 return 0;
}
     
/* textwidth example */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,j=0,k=0,error,maximumcolor;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 j = getmaxy() / 2;
 settextjustify(LEFT_TEXT, CENTER_TEXT);
 for (i = 1; i < 11; i++)
 {
 settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
 sprintf(message, "Size: %d", i);
 outtextxy(k, j, message);
 /* advance to the end of the text */
 k+= textwidth(message);
 }
 getch();
 closegraph();
 return 0;
}
     
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char range[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 sprintf(range, "X values range from 0..%d", getmaxx());
 outtextxy( getmaxx()/2,getmaxy()/2 ,range);
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char range[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 sprintf(range, "Y values range from 0..%d", getmaxy());
 outtextxy( getmaxx()/2,getmaxy()/2 ,range);
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//delay
int main()
 {
 int gd=DETECT,gm,error,i;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for(i=0;i<=getmaxy();i++)
 {
 cleardevice();
 sprintf(message, ".<<---(x=0,y=%d) :: www.CProgrammingExpert.com",i);
 outtextxy( 0,i ,message);
 delay(100);
 }
 getch();
 closegraph();
 return 0;
}

     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//delay
int main()
 {
 int gd=DETECT,gm,error,i;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for(i=0;i<=getmaxx();i++)
 {
 cleardevice();
 sprintf(message, ".<<---(x=%d,y=10) :: www.CProgrammingExpert.com",i);
 outtextxy( i,10 ,message);
 delay(100);
 }
 getch();
 closegraph();
 return 0;
}

     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for(i=1;i<=150;i+=10)
 {
 cleardevice();
 arc (310,250,360-i, (360-i)+150,i); 
 //void arc (int x, int y, int startangle, int endangle, int radius);
 outtextxy(getmaxx()-200,getmaxy()-100,"Center:(310,250)");
 sprintf(message, "Radius : %d",i);
 outtextxy(getmaxx()-200,getmaxy()-80,message);
 sprintf(message, "Start angle : %d ",360-i);
 outtextxy(getmaxx()-200,getmaxy()-60,message);
 sprintf(message, "End angle : %d",(360-i)+150);
 outtextxy(getmaxx()-200,getmaxy()-40,message);
 getch();
 }
 cleardevice();
 for(i=1;i<=150;i+=10)
 arc (310,250,360-i, (360-i)+150,i);
 outtextxy(getmaxx()-250,getmaxy()-40,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 bar (320,250, 250, 10);
 outtextxy(getmaxx()-200,getmaxy()-100,"Left : 320");
 outtextxy(getmaxx()-200,getmaxy()-80,"Top : 250");
 outtextxy(getmaxx()-200,getmaxy()-60,"Right : 250");
 outtextxy(getmaxx()-200,getmaxy()-40,"Bottom : 10");
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 setbkcolor(BLUE);
 bar3d(320,250, 250, 50,35,125);
 outtextxy(getmaxx()-200,getmaxy()-140,"Left : 250");
 outtextxy(getmaxx()-200,getmaxy()-120,"Top : 250");
 outtextxy(getmaxx()-200,getmaxy()-100,"Right : 250");
 outtextxy(getmaxx()-200,getmaxy()-80,"Bottom : 50");
 outtextxy(getmaxx()-200,getmaxy()-60,"Depth : 35");
 outtextxy(getmaxx()-200,getmaxy()-40,"Top Flag : 125");
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 setbkcolor(BLUE);
 for(i=10;i<=210;i+=10)
 {
 cleardevice();
 circle (320, 250,i); 
 outtextxy(getmaxx()-200,getmaxy()-60,"Center : (320,250)");
 sprintf(message, "Radius : %d",i);
 outtextxy(getmaxx()-200,getmaxy()-40,message);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 }
 cleardevice();
 for(i=10;i<=210;i+=10)
 circle (320, 250,i);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 int poly[10],maxx, maxy;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 setbkcolor(BLUE);
 maxx = getmaxx();
 maxy = getmaxy();
 poly[0] = 30; /* first vertex */
 poly[1] = maxy / 2;
 poly[2] = maxx - 30; /* second vertex */
 poly[3] = 30;
 poly[4] = maxx - 75; /* third vertex */
 poly[5] = maxy - 30;
 poly[6] = maxx / 2; /* fourth vertex */
 poly[7] = maxy / 2;
 poly[8] = poly[0]; /* drawpoly doesn't automatically close */
 poly[9] = poly[1]; /* the polygon, so we close it */
 drawpoly(5, poly); /* draw the polygon */
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,poly[10],maxx, maxy,i,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1); 
 }
 setbkcolor(BLUE);
 maxx = getmaxx();
 maxy = getmaxy();
 poly[0] = 30; 
 poly[1] = maxy / 2;
 poly[2] = maxx - 30; 
 poly[3] = 30;
 poly[4] = maxx - 75; 
 poly[5] = maxy - 30;
 poly[6] = maxx / 2; 
 poly[7] = maxy / 2;
 poly[8] = poly[0]; /* drawpoly doesn't automatically close */
 poly[9] = poly[1]; 
 for (i=EMPTY_FILL; i     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 line(0, 0, getmaxx(), getmaxy()); /* draw a line */
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,j,error;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for(i=50,j=100;i<=100;i+=10,j+=20)
 {
 cleardevice();
 ellipse (getmaxx()/2,getmaxy()/2,0,360,j+75, j); //<<<<<<<<<
 line(getmaxx()/2,getmaxy()/2,(getmaxx()/2)+j+75,getmaxy()/2);
 line(getmaxx()/2,getmaxy()/2,getmaxx()/2,(getmaxy()/2)-j);
 sprintf(message, "Center (%d,%d)",getmaxx()/2,getmaxy()/2);
 outtextxy(getmaxx()-200,getmaxy()-120,message);
 outtextxy(getmaxx()-200,getmaxy()-100,"Start agle : 0");
 outtextxy(getmaxx()-200,getmaxy()-80,"End angle : 360");
 sprintf(message, "xradius: %d ",j+75);
 outtextxy(getmaxx()-200,getmaxy()-60,message);
 sprintf(message, "yradius : %d",j);
 outtextxy(getmaxx()-200,getmaxy()-40,message);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 }
 cleardevice();
 for(i=50,j=100;i<=100;i+=10,j+=20)
 ellipse (getmaxx()/2,getmaxy()/2,0,360,j+75,j);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,i,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 /* loop through the fill patterns */
 for (i = EMPTY_FILL; i < USER_FILL; i++)
 {
 /* set fill pattern */
 setfillstyle(i, getmaxcolor());
 /* draw a filled ellipse */
 fillellipse(getmaxx() / 2, getmaxy() / 2,200, 150);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 }
 getch();
 closegraph();
 return 0;
}


     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* floodfill example */
#include <stdlib.h>
int main()
 {
 int gd=DETECT,gm,i,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor()); /* select drawing color */
 setfillstyle(SOLID_FILL, getmaxcolor()); /* select fill color */
 rectangle(0, 0, getmaxx(), getmaxy()); /* draw a border around the screen */
 circle(getmaxx() / 3, getmaxy() /2, 50);
 circle(getmaxx()-20, 10, 50);
 circle(100, 100, 50);
 circle(getmaxx() / 2, 20, 100);
 circle(getmaxx()-75, getmaxy()-25, 200);
 circle(20, getmaxy()-20, 25);
 getch();
 floodfill(2, 2, getmaxcolor()); /* fill in bounded region */
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getarccoords example */
int main()
 {
 int gd=DETECT,gm,error,stangle = 90, endangle = 360;
 struct arccoordstype info;
 char message1[80], message2[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 arc(getmaxx() / 2, getmaxy() / 2, stangle, endangle, 100); /* draw arc */
 getarccoords(&info;);
 /* convert arc information into strings */
 sprintf(message1, "*- (%d, %d)", info.xstart, info.ystart);
 sprintf(message2, "*- (%d, %d)", info.xend, info.yend);
 outtextxy(info.xstart, info.ystart, message1);
 outtextxy(info.xend, info.yend, message2);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getaspectratio example */
int main()
 {
 int gd=DETECT,gm,error,xasp, yasp;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 getaspectratio(&xasp;, &yasp;); /* get current aspect ratio settings */
 circle( getmaxx() / 2, getmaxy() / 2, 100);
 getch();
 cleardevice();
 setaspectratio(xasp/2, yasp);
 circle( getmaxx() / 2, getmaxy() / 2, 100); /* draw wide circle */
 getch();
 cleardevice();
 setaspectratio(xasp, yasp/2);
 circle( getmaxx() / 2, getmaxy() / 2, 100);
 getch();
 cleardevice();
 setaspectratio(xasp, yasp);
 circle( getmaxx() / 2, getmaxy() / 2, 100);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getfillpattern example */
int main()
 {
 int gd=DETECT,gm,error;
 char pattern[8] = {0x00, 0x70, 0x20,0x27, 0x25, 0x27, 0x04, 0x04};
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 setfillpattern(pattern,getmaxcolor()); /* select a user-defined fill pattern */
 bar(30, 30, getmaxx()-30, getmaxy()-30);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 getfillpattern(pattern); /* get the current user-defined fill pattern */
 pattern[0] -= 5; /* alter the pattern we grabbed */
 pattern[1] -= 10;
 pattern[2] += 10;
 pattern[3] -= 15;
 setfillpattern(pattern, getmaxcolor()); 
 /* fill the screen with the new pattern */
 bar(30, 30, getmaxx()-30, getmaxy()-30);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
 }


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getbkcolor example */
int main()
 {
 int gd=DETECT,gm,error,color;
 char name[35];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 color = getbkcolor(); 
 itoa(color, name, 10); /* convert color value into a string */
 strcat(name, " is the current background color.");
 /* display a message */
 outtextxy(getmaxx() / 2, getmaxy() / 2, name);
 outtextxy(getmaxx()-125,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include
/* getpixel example */
#define PIXEL_COUNT 1000
#define DELAY_TIME 100 /* in milliseconds */
int main()
 {
 int gd=DETECT,gm,error,i, x, y, color, maxcolor, seed;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 maxcolor = getmaxcolor() + 1;
 while (!kbhit()) 
 {
 seed = random(32767); 
 srand(seed); /* seed the random number generator */
 for (i=0; i     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//clearviewport()
int main()
 {
 int gd=DETECT,gm,error,height;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 height = textheight("l");
 outtextxy(0, 0, "* <-- (0, 0) in default viewport");
 setviewport(150, 150, getmaxx()-150, getmaxy()-150, 1); /* create a new viewport */
 outtextxy(0, 0, "* <-- (0, 0) in new viewport");
 outtextxy(0, 2*height, "Press any key to clear viewport:");
 getch();
 clearviewport(); /* clear the viewport */
 outtextxy(0, 0, "Press any key to quit:");
 outtextxy(getmaxx()-300,getmaxy()-10,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//settextjustify
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, "Press a key to close the graphics system:");
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 printf("Hi,We're now back in text mode.\n");
 printf("Press any key to halt:");
 getch();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//detectgraph
#include 
/* the names of the various cards supported */
char *dname[] = { "requests detection",
"a CGA",
"an MCGA",
"an EGA",
"a 64K EGA",
"a monochrome EGA",
"an IBM 8514",
"a Hercules monochrome",
"an AT&T; 6300 PC",
"a VGA",
"an IBM 3270 PC"
};
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 clrscr();
 printf("You have %s video display card.\n", dname[gd]);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 printf("Press any key to halt:");
 getch();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getcolor example */
int main()
 {
 int gd=DETECT,gm,error;
 int color, midx, midy;
 char colname[35];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 color = getcolor(); /* get the current drawing color */
 itoa(color, colname, 10); /* convert color value into a string */
 strcat(colname, " is the current drawing color.");
 outtextxy(getmaxx() / 2, getmaxy() / 2, colname);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* getdrivername example */
int main()
 {
 int gd=DETECT,gm,error;
 char *drivername;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setcolor(getmaxcolor());
 drivername = getdrivername(); /* get the name of the device driver in use */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 strcat(drivername," is currently loaded driver");
 outtextxy(getmaxx() / 2, getmaxy() / 2, drivername); /* output the name of the driver */
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}


     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 struct fillsettingstype fillinfo;
 char message1[50], message2[50];
 char *fillname[] = { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL",
"LTSLASH_FILL", "SLASH_FILL","BKSLASH_FILL", "LTBKSLASH_FILL",
"HATCH_FILL", "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL",
"CLOSE_DOT_FILL", "USER_FILL" }; /* The names of the fill styles supported */
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 getfillsettings(&fillinfo;); /* get info about current fill pattern and color */
 sprintf(message1, "%s is the fill style.", fillname[fillinfo.pattern]);
 sprintf(message2, "%d is the fill color.", fillinfo.color);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)-2*textheight("l"), message1);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), message2);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
 }

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,mode;
 char strnumber[80], strmode[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 mode = getgraphmode(); /* get mode number and name strings */
 sprintf(strnumber, "%d is the current mode number.", mode);
 sprintf(strmode, "%s is the current graphics mode.", getmodename(mode));
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, strnumber);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), strmode);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 struct linesettingstype lineinfo;
 char linestyle[80], linepattern[80], linewidth[80];
 char *linename[] = { "SOLID_LINE", "DOTTED_LINE", "CENTER_LINE",
"DASHED_LINE", "USERBIT_LINE" }; 
/* the names of the line styles supported */
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 getlinesettings(&lineinfo;); /* get information about current line settings */
 sprintf(linestyle, "%s is the line style.", linename[lineinfo.linestyle]);
 /* convert line information into strings */
 sprintf(linepattern, "0x%X is the user-defined line pattern.",lineinfo.upattern);
 sprintf(linewidth, "%d is the line thickness.", lineinfo.thickness);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2,getmaxy() / 2, linestyle);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), linepattern);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+4*textheight("l"), linewidth);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char colstr[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); 
/* grab the color info. and convert it to a string */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2,getmaxy() / 2, colstr);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char modestr[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 sprintf(modestr, "This driver supports modes 0..%d",getmaxmode());
 /* grab the mode info. and convert it to a string */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2,getmaxy() / 2, modestr);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,mode;
 char strnumber[80], strmode[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 mode = getgraphmode(); /* get mode number and name strings */
 sprintf(strnumber, "%d is the current mode number.", mode);
 sprintf(strmode, "%s is the current graphics mode.",getmodename(mode));
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, strnumber);
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("W"), strmode);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setwritemode(XOR_PUT); /* select XOR drawing mode */
 line(0, 0, getmaxx(), getmaxy());
 getch();
 line(0, 0, getmaxx(), getmaxy()); /* erase the line by drawing over it */
 getch();
 setwritemode(COPY_PUT); /* select overwrite drawing mode */
 line(0, 0, getmaxx(), getmaxy());
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gdriver = EGA, gmode = EGAHI, error,height;
 initgraph(&gdriver;,&gmode;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 height = textheight("l");
 setactivepage(1); /* select the off screen page for drawing */
 circle(getmaxx()/2,getmaxy()/2,150); /* draw a circle on page #1 */
 settextjustify(CENTER_TEXT, CENTER_TEXT); 
/* output a message on page #1 */
 outtextxy(getmaxx() / 2, getmaxy() / 2, "This is page #1:");
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+height, "Press any key to halt:");
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 setactivepage(0); /* select drawing to page #0 */
 ellipse (getmaxx()/2,getmaxy()/2,0,360,150, 100);
 outtextxy(getmaxx() / 2, getmaxy() / 2, "This is page #0.");
 outtextxy(getmaxx() / 2, (getmaxy() / 2)+height, "Press any key to view page #1:");
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 /* select page #1 as the visible page */
 setvisualpage(1);
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,a,b,result;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 circle(getmaxx()/2,getmaxy()/2,175);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, "Press a key to close the graphics system:");
 getch();
 closegraph(); /* closes down the graphics system */
 printf("*****We're now back in text mode.*****\n\n");
 printf("Enter two numbers\n");
 scanf("%d%d",&a;,&b;);
 result=a+b;
 printf("\nSum of %d and %d is %d\n\nOK!",a,b,result);
 getch();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
 moveto(getmaxx() / 2, getmaxy() / 2); /* move to the text starting position */
 outtext("Norm ");
 setusercharsize(1, 2, 1, 1); outtext("Short "); /* make the text 1/2 the normal width */
 setusercharsize(3, 1, 1, 1); outtext("Wide"); /* make the text 3 times normal width */
 settextstyle(GOTHIC_FONT, HORIZ_DIR, 1);
 outtextxy(getmaxx()/2,getmaxy()-30,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* the names of the text styles supported */
char *styles[] = { "DEFAULT font", "TRIPLEX font",
"SMALL font", "SANS SERIF_font",
"GOTHIC_font", "SCRIPT font","SIMPLEX font", 
"TRIPLEX SCRIPT font","COMPLEX font", 
"EUROPEAN font","BOLD font"};
int main()
 {
 int gd=DETECT,gm,error,i,style,size = 1;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 for (i=DEFAULT_FONT; i<=BOLD_FONT; i++) 
/* loop through the available text styles */
 {
 cleardevice();
 if (i == TRIPLEX_FONT)
 size = 3;
 settextstyle(i, HORIZ_DIR, size); /* select the text style */
 outtextxy( getmaxx() / 2, getmaxy() / 2,styles[i]);
 outtextxy(getmaxx()-250,getmaxy()-25,"www.CProgrammingExpert.com");
 getch();
 }
 closegraph();
 return 0;
 }

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i, height, j=0;
 struct palettetype type;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 getpalette(&type;); /* grab a copy of the palette */
 for (i=0; i     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,x,y;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 x=getmaxx() / 2;
 y=getmaxy() / 2;
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 rectangle(x-175, y-50, x+175, y+50);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 outtextxy(x, y, "Press any key to exit graphics");
 getch();
 restorecrtmode(); /* restore system to text mode */
 printf("We're now in text mode.\n");
 printf("Press any key to return to graphics mode:");
 getch();
 setgraphmode(getgraphmode()); /* return to graphics mode */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 setbkcolor(BLUE);
 outtextxy(x, y, "We're back in graphics mode.");
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 outtextxy(x, y+2*textheight("l"), "Press any key to return to text mode:");
 getch();
 restorecrtmode(); /* restore system to text mode */
 printf("We're now in text mode.\n");
 printf("Press any key to halt:");
 getch();
 closegraph();
 return 0;
 }

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
char *linename[] = { "SOLID_LINES", "DOTTED_LINES",
 "CENTER_LINES","DASHED_LINES", "USERBIT_LINES" }; 
/* The names of the line styles supported */
int main()
 {
 int gd=DETECT,gm,error,i;
 int style, midx, midy, userpat;
 char stylename[25],message[25];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 userpat = 1;
for(i=1;i<=3;i++)
 {
 for (style=SOLID_LINE; style<=USERBIT_LINE; style++)
 {
 sprintf(message, "Line thickness : %d",i);
 outtextxy(midx-75, midy-100, message);
 setlinestyle(style, userpat, i); /* select the line style */
 strcpy(stylename, linename[style]); /* convert style into a string */
 rectangle(10, 10, getmaxx()-10, getmaxy()-10);
 line(10, 10, midx-10, midy);
 line(midx-10, midy, getmaxx()-10,getmaxy()-10);
 line(midx-10, midy, getmaxx()-10,10);
 line(midx-10, midy,10,getmaxy()-10);
 outtextxy(midx, midy, stylename);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 cleardevice();
 }
 getch();
 }
closegraph();
return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error, color, maxcolor, height,y = 10;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 maxcolor = getmaxcolor();
 height = 2 * textheight("l");
 for (color=1; color<=maxcolor; color++) /* display the default colors */
 {
 setcolor(color);
 sprintf(msg, "Color: %d", color);
 outtextxy((getmaxx()/2)-50, y, msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 y += height;
 }
 getch();
 for (color=1; color<=maxcolor; color++) /* red out the colors one by one */
 {
 setpalette(color, RED);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 }
closegraph();
return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define BUFSIZE 1000 /* internal graphics buffer size */
int main()
 {
 int gd=DETECT,gm,i,error;
 int x, y, oldsize;
 char msg[80];
 oldsize = setgraphbufsize(BUFSIZE); 
/* Set size of internal graphics buffer before calling initgraph*/
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 x = getmaxx() / 2;
 y = getmaxy() / 2;
 sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(x, y-25, msg);
 sprintf(msg, "Old graphics buffer size: %d", oldsize);
 outtextxy(x, y+2*textheight("l"), msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* the names of the fill styles supported */
char *fname[] = { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL",
"LTSLASH_FILL", "SLASH_FILL", "BKSLASH_FILL", 
"LTBKSLASH_FILL","HATCH_FILL", "XHATCH_FILL", 
"INTERLEAVE_FILL", "WIDE_DOT_FILL",
"CLOSE_DOT_FILL", "USER_FILL" };
int main()
 {
 int gd=DETECT,gm,error,i;
 int style, midx, midy;
 char stylestr[40];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 for (style = EMPTY_FILL; style < USER_FILL; style++)
 {
 setfillstyle(style, getmaxcolor()); /* select the fill style */
 strcpy(stylestr, fname[style]); /* convert style into a string */
 /* fill a bar */
 bar3d(midx-125, midy-125, midx+10, midy, 10, 10);
 outtextxy(midx+10, midy, stylestr);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 cleardevice();
 }
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,left, top, right, bottom;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 left = getmaxx() / 2 -200;
 top = getmaxy() / 2 - 200;
 right = getmaxx() / 2 + 200;
 bottom = getmaxy() / 2 + 200;
 rectangle(left,top,right,bottom); /* draw a rectangle */
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error, midx, midy, i;
 int stangle = 0, endangle = 270, xrad = 200, yrad = 150;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 for (i=EMPTY_FILL; i     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,low, high;
 char moderange[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 getmoderange(gd, &low;, &high;); /* get the mode range for this driver */
 sprintf(moderange, "This driver supports modes %d..%d", low, high); 
/* convert mode range info. into strings */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, moderange);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char palettesize[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 sprintf(palettesize, "The palette has %d modifiable entries.",getpalettesize()); 
/* convert palette size info into string */
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 outtextxy(getmaxx() / 2, getmaxy() / 2, palettesize);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i,j = 10,height;
 struct palettetype pal;
 char palettesize[80], paletteval[20];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 getpalette(&pal;); /* grab a copy of the palette */
 sprintf(palettesize, "The palette has %d modifiable entries.",pal.size);
 /* convert palette info into strings */
 outtextxy(getmaxx()/2-175, j, palettesize);
 if (pal.size != 0)
 {
 height = textheight("l");
 j += 2*height;
 outtextxy(getmaxx()/2-125, j, "Here are the current values:");
 j += 2*height;
 for (i=0; i     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
char *clip[] = { "OFF", "ON" };
int main()
 {
 int gd=DETECT,gm,error, midx, midy, ht;
 struct viewporttype viewinfo;
 char topstr[80], botstr[80], clipstr[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk)
 {
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 getviewsettings(&viewinfo;); /* get information about current viewport */
 sprintf(topstr, "(%d, %d) is the upper left viewport corner.",viewinfo.left, viewinfo.top);
 sprintf(botstr, "(%d, %d) is the lower right viewport corner.",viewinfo.right, viewinfo.bottom);
 sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]);
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 ht = textheight("W");
 outtextxy(midx, midy, topstr);
 outtextxy(midx, midy+2*ht, botstr);
 outtextxy(midx, midy+4*ht, clipstr);
 outtextxy(getmaxx()-150,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(getmaxx() / 2, getmaxy() / 2); /* move to the screen center point */
 sprintf(msg, "<-(%d, %d) is the here.", getx(), gety());
 outtext(msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(getmaxx() / 2-100, getmaxy() / 2+25); /* move to the screen center point */
 sprintf(msg, "<-(%d, %d) is the here.", getx(), gety());
 outtext(msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setlinestyle(DOTTED_LINE, 0, 3);
 rectangle(10, 10, getmaxx()-10,getmaxy()-10);
 outtextxy(getmaxx()/2-100, getmaxx()/3, "Before default values are restored.");
 outtextxy(getmaxx()-250,getmaxy()-30,"www.CProgrammingExpert.com");
 getch();
 graphdefaults(); /* restore default values for everything */
 cleardevice();
 rectangle(10, 10, getmaxx()-10,getmaxy()-10);
 /* output rectangle with default settings */
 outtextxy(getmaxx()/2-100, getmaxy()/3, "After restoring default values.");
 outtextxy(getmaxx()-250,getmaxy()-30,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define NONSENSE -50
int main()
 {
 int gd=NONSENSE,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error: %s\n", grapherrormsg(error));
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 rectangle(10, 10, getmaxx()-10,getmaxy()-10);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define ARROW_SIZE 10
void draw_arrow(int x, int y);
int main()
 {
 int gd=DETECT,gm,error,i;
 void *arrow;
 int x, y, maxx;
 unsigned int size;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 maxx = getmaxx();
 x = 0;
 y = getmaxy() / 2;
 draw_arrow(x, y); /* draw the image to be grabbed */
 size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
 /* calculate the size of the image */
 arrow = malloc(size); /* allocate memory to hold the image */
 getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
 /* grab the image */
 while (!kbhit()) /* repeat until a key is pressed */
 {
 putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); /* erase old image */
 x += ARROW_SIZE;
 if (x >= maxx)
 x = 0;
 putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); /* plot new image */
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 }
 free(arrow);
 closegraph();
 return 0;
}


void draw_arrow(int x, int y)
 {
 moveto(x, y); /* draw an arrow on the screen */
 linerel(4*ARROW_SIZE, 0);
 linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
 linerel(0, 2*ARROW_SIZE);
 linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
 }

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char message[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(100,100); /* move the CP to location (100,100) */
 sprintf(message, " (%d, %d)", getx(), gety()); 
/* create and output a message at (100,100) */
 outtextxy(100,100, message);
 linerel(200, 200);
 /* draw line to a point a relative distance away from current CP*/
 sprintf(message, " (%d, %d)", getx(), gety());
 /* create and output a message at CP */
 outtext(message);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(100, 100); /* move the CP to location (100,100) */
 sprintf(msg, " (%d, %d)", getx(), gety()); /* create and output a message at (100,100) */
 outtextxy(100,100, msg);
 lineto(200, 200); /* draw a line to (100,100) */
 sprintf(msg, " (%d, %d)", getx(), gety()); /* create and output a message at CP */
 outtext(msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
/* moverel example */
int main()
 {
 int gd=DETECT,gm,error;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(100,100);
 putpixel(getx(), gety(), getmaxcolor()); /* plot a pixel at the CP */
 sprintf(msg, " (%d, %d)", getx(), gety());
 outtextxy(100,100, msg);
 moverel(200, 200);
 putpixel(getx(), gety(), getmaxcolor()); /* plot a pixel at the CP */
 sprintf(msg, " (%d, %d)", getx(), gety()); 
/* create and output a message at CP */
 outtext(msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     


        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,i;
 char msg[80];
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 moveto(100,100);
 putpixel(getx(), gety(), getmaxcolor());
 sprintf(msg, " (%d, %d)", getx(), gety());
 outtextxy(100,100, msg);
 moveto(200,200);
 putpixel(getx(), gety(), getmaxcolor());
 sprintf(msg, " (%d, %d)", getx(), gety());
 outtext(msg);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
 {
 int gd=DETECT,gm,error,stangle = 45, endangle = 135, radius = 200;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 setfillstyle(EMPTY_FILL, getmaxcolor()); /* set fill style and draw a pie slice */
 pieslice(getmaxx() / 2, getmaxy() / 2, stangle, endangle, radius);
 outtextxy(getmaxx()-250,getmaxy()-20,"www.CProgrammingExpert.com");
 getch();
 closegraph();
 return 0;
}

     



        

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
//outtext
int main()
 {
 int gd=DETECT,gm,error;
 initgraph(&gd;,&gm;,"f:\\tc\\bgi");
 error = graphresult();
 if (error != grOk) 
 { 
 printf("Graphics error occurred");
 printf("Press any key to halt:");
 getch();
 exit(1);
 }
 setbkcolor(BLUE);
 for (i=SOLID_FILL; i     

Home

Goto statement

The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program unconditionally. In its general form, the goto statement is written as

goto label;

                   where the label is an identifier that is used to label the target statement to which the control is transferred. Control may be transferred to anywhere within the current function. The target statement must be labeled, and a colon must follow the label. Thus the target statement will appear as

label:statement;

Each labeled statement within the function must have a unique label, i.e., no two statement can have the same label.

The following program illustrates the use of  goto statement.

Home

String

 

                        A string in C is actually a character array. As an individual character variable can store only one character, we need an array of characters to store strings. Thus, in C string is stored in an array of characters. Each character in a string occupies one location in an array. The null character ‘\0’ is put after the last character. This is done so that program can tell when the end of the string has been reached. For example, the string ”I Like C Programming” is stored as follows.

I   L i k e   C   P r o g r a m m i n g \o

Since the string has 20 characters (including space), it requires an arrayof at least, size 21 to store it.

                       Thus, in C, a string is a one-dimensional array of characters terminated a null character. The terminating null character is important. In fact, a string not terminated by ‘\0’ is not really a string, but merely a collection of characters.

                      A string may contain any character, including special control characters, such as \n\t\\ etc…

                      There is an important distinction between a string and a single character in C. The convention is that single characters are enclosed by single quotes e.g. ‘*’ and have the type char. Strings, on the hand, are enclosed by double quotes e.g. “name” and have the type “pointer to char” (char *) or array of char.

                      Strings can be declared in two main ways; one of these is as an array of characters, the other is as a pointer to some pre-assigned array. Perhaps the simplest way of seeing how C stores arrays is to give an extreme example which would probably never be used in practice.

#include<stdio.h>
int main ()
       {
       char string[];
       string[0] = ‘C’;
       string[1] = ‘P’;
       string[2] = ‘r’;
       string[3] = ‘o’;
       string[4] = ‘g’;
       string[5] = ‘r’;
       string[6] = ‘a’;
       string[7] = ‘m’;
       string[8] = ‘m’;
       string[9] = ‘i’;
       string[10]= ‘n’;
       string[11] = ‘g’;
       printf (“%s”, string);
       return 0;
      }

                          This method of handling strings is perfectly acceptable, if there is time to waste, but it is so laborious that C provides a special initialization service for strings, which bypasses the need to assign every single character with a new assignment!.

The other way is use a pointer to some pre-assigned array.

#include<stdio.h>
int main ()
      {
      char str1[]=”I Like”;
      char *str2=”C Programming”;
      puts(str1);
      puts(str2);
      return 0;
}
Home

IO Functions

The usually used input statement is scanf () function.

Syntax of scanf function is
                  scanf (“format string”, argument list);

                The format string must be a text enclosed in double quotes. It contains the information for interpreting the entire data for connecting it into internal representation in memory.
Example: integer (%d) , float (%f) , character (%c) or string (%s).

                The argument list contains a list of variables each preceded by the address list and separated by comma. The number of argument is not fixed; however corresponding to each argument there should be a format specifier. Inside the format string the number of argument should tally with the number of format specifier.

               Example: if i is an integer and j is a floating point number, to input these two numbers we may use
scanf (“%d%f”, &i, &j);

Program:

Home

SEO Expert india (local services)

Dear Internet friend,
Are you looking for an seo expert india ?
Are you looking for someone to help your seo work?
Do you need more traffic to your website?
Do you want to make more money from your website by getting more traffic?
Do you want to earn more Adsense revenue? If ‘Yes’ I can help you.

Home

Sourcecode

1.check prime numbers source code

#include
#include
void main()
{
int l,i,j,f,n;
clrscr();
do
 {
 printf("\n[1] to check prime number\n");
 printf("[2] to generate prime numbers upto a given number\n");
 printf("[3] to exit\nEnter yor choice\n");
 scanf("%d",&l;);
 switch(l)
  {
  case 1:
     {
     printf("enter a number\n");
     scanf("%d",&n;);
     f=1;
     for(i=2;i

2.Matrix operation

#include
#include
void input(int z);
void multiply(void);
void add(void);
void display(void);
void transpose(void);
int r1,r2,c1,c2,c,m1[5][5],m2[5][5],m3[5][5],i,j,k,d=0;
void main()
{
clrscr();
do
 {
 printf("enter [1] to add two matrices\n");
 printf("enter [2] to perform matrix multiplication\n");
 printf("enter [3] to find traspose of a matrix\n");
 printf("enter [4]  exit\n");
 printf("enter your choice\n");
 scanf("%d",&c;);
 switch(c)
   {
   case 1:
      input(c);
      if(d!=1)
       {
       add();
       display();
       }
   break;
   case 2:
      input(c);
      if(d!=1)
 {
 multiply();
 display();
 }
   break;
   case 3:
      input(c);
      if(d!=1)
 {
 transpose();
 display();
 }
   break;
   case 4:
   break;
   default:
      printf("invalid input\n");
   break;
   }
}
while(c!=4);
getch();
}

void input(int z)
   {
   d=0;
   printf("enter r1 and c1\n");
   scanf("%d%d",&r1;,&c1;);
   if(z!=3)
     {
      printf("enter r2 and c2\n");
      scanf("%d%d",&r2;,&c2;);
      }
   if((z==1)&&(r1==r2)&&(c1==c2)||(z==2)&&(c1==r2))
     {
     printf("enter elements of matrix 1\n");
     for(i=0;i




3.stack using linked list
#include
#include
#define null 0
struct linkedlist
   {
   int info;
   struct linkedlist *next;
   };
typedef struct linkedlist node;
void create(node *list);
node *deletee(node *list);
void display(node *list);
node *insert(node *list);
int i=1;

void main()
   {
   int x;
   node *head;
   clrscr();
   head=(node *)malloc(sizeof(node));
   create(head);
   display(head);
   printf("\nhow many numbers you want to push to stack\n");
   scanf("%d",&x;);
   for(i=1;i<=x;i++)
      head=insert(head);
   printf("after insertion\n");
   display(head);
   printf("\nhow many numbers you want to pop from stack\n");
   scanf("%d",&x;);
   for(i=1;i<=x;i++)
     head=deletee(head);
   printf("after deletion\n");
   display(head);
   getch();
   }


void create(node *list)
      {
      printf("enter %d-th number(0 to exit) \n",i);
      scanf("%d",&(list->info));
      i++;
      if(list->info==0)
   list->next=null;
      else
   {
    list->next=(node *)malloc(sizeof(node));
    create(list->next);
   }
   }


 void display(node *list)
   {
   while(list->next!=null)
      {
      printf("%d->",list->info);
      list=list->next;
      }
   }

node *insert(node *list)
   {
   int x;
   node *new,*i;
   printf("value of new item\n");
   scanf("%d",&x;);
   new=(node *)malloc(sizeof(node));
   new->info=x;
   for(i=list;i->next->next!=null;i=i->next)
     ;
   new->next=i->next;
   i->next=new;
   return(list);
   }

node *deletee(node *list)
   {
   int x;
   node *i;
   for(i=list;i->next->next!=null;i=i->next)
     ;
   i->next=null;
   return(list);
   }





4. Linked list 

#include
#include
#define null 0
struct linkedlist
   {
   int info;
   struct linkedlist *next;
   };
typedef struct linkedlist node;
void create(node *list);
void display(node *list);
void sort(node *list);
/*node* find(node *list,int);*/
int i=1;

void main()
   {
   node *head1,*head2,*head3;
   clrscr();
   head1=(node *)malloc(sizeof(node));
   printf("Linked List A:\n");
   create(head1);
   printf("elements of linked list A is:\n");
   display(head1);
   head2=(node *)malloc(sizeof(node));
   printf("\n\nLinked List B:\n");
   create(head2);
   printf("elements of linked list B is:\n");
   sort(head1);
   sort(head2);
   display(head2);
   getch();
   }


void create(node *list)
      {
      printf("enter %d-th number(0 to exit) \n",i);
      scanf("%d",&(list->info));
      i++;
      if(list->info==0)
   list->next=null;
      else
   {
    list->next=(node *)malloc(sizeof(node));
    create(list->next);
   }
      i=0;
   }

 void display(node *list)
   {
      if(list->next==null)
  printf("list is empty\n");
      else
  {
  while(list->next!=null)
      {
      printf("%d-->",list->info);
      list=list->next;
      }
 }
    }


     
     
c coding

Home

Turbo C++ Integrated Development Environment

              IDE is nothing but Integrated Development Environment in which one can develop, run, test and debug the application. The Turbo C++ IDE appears as shown in figure.

              The C Developing Environment is a screen display with windows and pull-down menus. The program listing, error messages and other information are displayed in separate windows. The menus may be used to invoke all the operations necessary to develop the program, including editing, compiling, linking, and debugging and program execution. If the menu bar is inactive, it may be invoked by pressing the [F10] function key. To select different menu, move the highlight left or right with cursor (arrow) keys. You can also revoke the selection by pressing the key combination for the specific menu.

Invoking the IDE

              The default directory of Turbo C compiler is c:\tc\bin. So to invoke the IDE from the windows you need to double click the TC icon in the directory c:\tc\bin.

               The alternate approach is that we can make a shortcut of tc.exe on the desktop.

Opening New Window

To type a program, you need to open an Edit Window. For this, open file menu and click “new”. A window will appear on the screen where the program may be typed.

Writing a Program

When the Edit window is active, the program may be typed. Use the certain key combinations to perform specific edit functions.

Saving a Program

To save the program, select save command from the file menu. This function can also be performed by pressing the [F2] button. A dialog box will appear asking for the path and name of the file.Provide an appropriate and unique file name. You can save the program after compiling too but saving it before compilation is more appropriate. 

Making an Executable File

The source file is required to be turned into an executable file. This is called “Making” of the .exe file. The steps required to create an executable file are:

1. Create a source file, with a .c extension.
2. Compile the source code into a file with the .obj extension.
3. Link your .obj file with any needed libraries to produce an executable program
All the above steps can be done by using Run option from the menu bar or using key combination Ctrl+F9 (By this linking & compiling is done in one step).

Compiling and linking in the IDE

                    In the Turbo C IDE, compiling and linking can be performed together in one step. There are two ways to do this: you can select Make EXE from the compile menu, or you can press the [F9] key

Correcting Errors

If the compiler recognizes some error, it will let you know through the Compiler window. You’ll see that the number of errors is not listed as 0, and the word “Error” appears instead of the word “Success” at the bottom of the window. The errors are to be removed by returning to the edit window. Usually these errors are a result of a typing mistake. The compiler will not only tell you what you did wrong, they’ll point you to the exact place in your code where you made the mistake.

Executing a Program

If the program is compiled and linked without errors, the program is executed by selecting Run from the Run Menu or by pressing the [Ctrl+F9] key combination.

Exiting IDE

                     An Edit window may be closed in a number of different ways. You can click on the small square in the upper left corner, you can select close from the window menu, or you can press the Alt+F3 combination. To exit from the IDE, select Exit from the File Menu or press Alt+X Combination.

Home