Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

C > Games and Graphics Code Examples

ARCHERY GAME

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
/* ARCHERY GAME */ #include<graphics.h> #include<stdio.h> #include<conio.h> #include<dos.h> #include<stdlib.h> union REGS i,o; int f; struct arccoordstype arcinfo; int t,flag=0; int gm=0,gd=DETECT,*button,*a,*b,c,bc,j,k,jk,h,x3,y3,alh=0,s,scor=0,sp=0,e,m=2 ; main() { //initgraph(&gm,&gd," "); front(); closegraph(); //delay(10); //sta(); a: initgraph(&gd,&gm," "); flag=0; setbkcolor(0); s=-60;e=60; sound(221.38); for(f=1;f<=20;f++) { setcolor(BLUE); line(280,f+360,360,f+360); } setcolor(RED); settextstyle(SMALL_FONT,HORIZ_DIR,4); outtextxy(305,364,"SHOOT"); arrows(0); setcolor(GREEN+WHITE); rectangle(5,5,634,474); rectangle(6,6,633,473); setcolor(YELLOW); rectangle(7,7,632,472); setcolor(GREEN+WHITE); rectangle(8,8,631,471); rectangle(9,9,630,470); rectangle(10,10,629,469); setcolor(YELLOW); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); outtextxy(530,20,"SCORE"); scor=0; score(200); m=6; equip(); arrow1(0,14); alh=0; mousereg(); while(m>1) /* while start */ { //button=0; for(j=-70;j<=70;j+=2) /* start for*/ { c=1; tar(j,c); delay(10); getmouseptr(&button,&a,&b); if(button==1) { x3=a;y3=b; if((x3>280 && x3<360 )|| (y3>361 && y3<379)) { bc=1; } } if(bc==1) { //sound(277.38); // delay(10); nosound(); arrow1(0,0); setcolor(YELLOW); line(40+sp+36,240,80+sp+36,240); line(80+sp+36,240,75+sp+36,235); line(80+sp+36,240,75+sp+36,245); line(40+sp+36,241,80+sp+36,241); line(79+sp+36,240,74+sp+36,236); line(79+sp+36,241,74+sp+36,245); line(46+sp+36,240,41+sp+36,236); line(46+sp+36,241,41+sp+36,245); line(42+sp+36,240,37+sp+36,236); line(42+sp+36,241,37+sp+36,245); delay(8); setcolor(0); line(40+sp+36,240,80+sp+36,240); line(80+sp+36,240,75+sp+36,235); line(80+sp+36,240,75+sp+36,245); line(40+sp+36,241,80+sp+36,241); line(79+sp+36,240,74+sp+36,236); line(79+sp+36,241,74+sp+36,245); line(46+sp+36,240,41+sp+36,236); line(46+sp+36,241,41+sp+36,245); line(42+sp+36,240,37+sp+36,236); line(42+sp+36,241,37+sp+36,245); if((42+sp+36)>=116 && (42+sp+36)<=136) { equip(); } sp=sp+3; } if((sp+80+36)>=579) { arrow1(0,14); score(j); bc=0; sp=0; alh++; button=0; setcolor(YELLOW); arrows(alh); m--; } // sp=sp+3; c=0; tar(j,c); } /* for end */ }/* while end */ sleep(1.5); closegraph(); gaover(); setcolor(GREEN); setcolor(1); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4); outtextxy(255,117,"SCORE"); setcolor(14+BLUE); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,3); for(t=0;t<=360;t++) { setcolor(random(15)); ellipse(300,200,t,t+2,30,22); delay(1); setcolor(random(15)); ellipse(300,200,t,t+2,35,25); } setcolor(GREEN); select(scor,-250,133); for(t=0;t<=50;t++) { setcolor(14); line(40+t,230,40+t,250); line(560+t,230,560+t,250); } settextstyle(SMALL_FONT,HORIZ_DIR,4); setcolor(BLUE); outtextxy(45,235,"Continue"); outtextxy(575,235,"Quit"); restrictmouseptr(0,80,640,440); flag=0; while(flag==0) { showmouseptr(); getmouseptr(&button,&a,&b); if(button==1) { x3=a;y3=b; if((x3>41 && x3<79 )&& (y3>231 && y3<249)) { flag=1; //break; } else if((x3>=561 && x3<=599 )&& (y3>=231 && y3<=249)) { flag=2; //break; } } } if(flag==1) goto a; else {if(flag==2) {initgraph(&gd,&gm,""); finalwindow(); closegraph(); goto b;}} // next(); b: getch(); }//ending of main function /* sub function target starting*/ arrow1(int sp,int col) { setcolor(col); //sound(277.38); line(40+sp+36,240,80+sp+36,240); line(80+sp+36,240,75+sp+36,235); line(80+sp+36,240,75+sp+36,245); line(40+sp+36,241,80+sp+36,241); line(79+sp+36,240,74+sp+36,236); line(79+sp+36,241,74+sp+36,245); line(46+sp+36,240,41+sp+36,236); line(46+sp+36,241,41+sp+36,245); line(42+sp+36,240,37+sp+36,236); line(42+sp+36,241,37+sp+36,245); nosound(); } tar(j,c) { setcolor(c*4); ellipse(579,240+j,0,360,40,90); setcolor(c*3); ellipse(579,240+j,0,360,33,75); setcolor(c*5); ellipse(579,240+j,0,360,26,60); setcolor(c*9); ellipse(579,240+j,0,360,19,45); setcolor(c*8); ellipse(579,240+j,0,360,12,30); setcolor(c*10); ellipse(579,240+j,0,360,5,15); } initmouse() { i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { i.x.ax=1; int86(0x33,&i,&o); } restrictmouseptr(int x1,int y1,int x2,int y2) { i.x.ax=7; i.x.cx=x1; i.x.dx=x2; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=y1; i.x.dx=y2; int86(0x33,&i,&o); } getmouseptr(int *button,int *a,int *b) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *a=o.x.cx; *b=o.x.dx; } mousereg() { int x1,x2,y1,y2,ce,k; initmouse(); showmouseptr(); restrictmouseptr(281,361,359,379); } arrows(alh) { int z=0,r; r=5-alh; setcolor(YELLOW); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); outtextxy(30,20,"ARROWS REMAINING"); for(f=r,z=0;f>0;f--) { line(40,60+z*10,80,60+z*10); line(80,60+z*10,75,55+z*10); line(80,60+z*10,75,65+z*10); z=z+1; } for(f=alh,z=0;f>0;f--) { setcolor(0); line(40,60+z*10,80,60+z*10); line(80,60+z*10,75,55+z*10); line(80,60+z*10,75,65+z*10); z=z+1; } } score (int j) { if( (j>=-90 && j<=-74) || (j>=74 && j<=90)) scor=scor+10; else if((j>=-72 && j<=-60) || (j>=60 && j<=72)) scor=scor+20; else if((j>=-58 && j<=-42) || (j>=42 && j<=58)) scor=scor+30; else if((j>=-40 && j<=-32) || (j>=32 && j<=40)) scor=scor+40; else if((j>=-30 && j<=-18) || (j>=18 && j<=30)) scor=scor+50; else if((j>=-16 && j<=0) || (j>=0 && j<=16)) scor=scor+60; else if (j == 300) scor=0; for(jk=50;jk<=120;jk++) {setcolor(0); line(530,jk,620,jk); } setcolor(YELLOW); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); select(scor,0,0); } front1() { int gm=0,gd=DETECT,i,j,k,jk,gh; initgraph(&gd,&gm," "); setcolor(MAGENTA); rectangle(10,10,639,469); rectangle(12,12,637,467); for(i=12;i<=627;i+=12) { setcolor(YELLOW); line(i,12,i,467); //clearviewport(); for(j=15;j<=464;j+=5) ellipse(i+6,j,-180,0,6,4); } for(i=3;i<=452;i+=5) { for(j=15;j<=627;j+=3) {setcolor(0); ellipse(j,467-i,-180,0,3,4); }delay(40); setcolor(BLACK); for(k=1;k<=5;k++) { line(12,467-i+k,637,467-i+k); } //setcolor(25); setcolor(GREEN+MAGENTA+WHITE+BLUE+YELLOW); rectangle(10,10,639,469); rectangle(12,12,637,467); } setcolor(2); rectangle(290,370,350,380); rectangle(292,372,348,378); gh=292; //gh<=388; for(j=1;j<=56;j+=1) { /* for(i=24;i<=627;i+=12) {setcolor(i); circle(i,23,3); delay(1); } */ jk=20; for(i=24;i<=627;i+=12) {setcolor(random(15)); circle(i,23,3); sound(440+jk); delay(10); nosound(); setcolor(YELLOW); rectangle(gh,372,gh,378); //rectangle(282,362,358,388);} jk+=40; if(jk>=880) { jk=440;} } gh=gh+1; nosound(); } sleep(.1); closegraph(); } equip() { int kl=2; int midx, midy,i,j,k,y=90,c; // int stangle = 45, endangle = 270; c=y/2; for(c=50;c<=52;c+=1) { setcolor(kl); line(26+c,170,26+c,310); } for(c=50;c<=54;c+=1) { setcolor(kl); line(60+c,222,60+c,255); } for(c=180;c<=270;c++) { // arc(80,92,c,c+1,20); setcolor(0); arc(86,166,c,c+1,10); getarccoords(&arcinfo); setcolor(kl); circle(arcinfo.xend, arcinfo.yend,2); } for(c=-50;c<=110;c++) { // arc(80,92,c,c+1,20); setcolor(0); arc(96,201,c,c+1,28); getarccoords(&arcinfo); setcolor(kl); circle(arcinfo.xend, arcinfo.yend,2); } for(c=50,i=4;c>=-110;c--) { // arc(80,92,c,c+1,20); setcolor(0); line(127,170,127,315); line(126,170,126,315); arc(96,278,c,c+1,28); getarccoords(&arcinfo); setcolor(kl); i=i+2; if(i>14) {i=2;} circle(arcinfo.xend,arcinfo.yend,2); } for(c=90;c<=180;c++) { // arc(80,92,c,c+1,20); setcolor(0); arc(86,314,c,c+1,10); getarccoords(&arcinfo); setcolor(kl); circle(arcinfo.xend, arcinfo.yend,2); //setcolor(2); } } sta() { int x,y=200,i,st,kl; //initgraph(&gd,&gm,""); setcolor(5); for(st=190,i=2;st>=-20;st-=9,i+=3) { setcolor(GREEN); arc(320,290,st,st+2,190); getarccoords(&arcinfo); delay(5); x=arcinfo.xend; y=arcinfo.yend; sound(300-st); star(x,y); delay(24); } for(st=190,i=2;st>=-17;st-=9,i+=3) { setcolor(YELLOW); arc(320,285,st,st+2,230); getarccoords(&arcinfo); delay(5); x=arcinfo.xend; y=arcinfo.yend; sound(320-st); star(x,y); delay(24); } nosound(); settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); for(i=140;i>=20;i-=10) { setcolor(8); delay(13); ya(i); delay(13); setcolor(4); r(i); delay(13); setcolor(2); e1(i); delay(13); h1(i); delay(13); c1(i); delay(13); r1(i); delay(13); a1(i); delay(13); /*line(320,240,325,233); // /1 line(325,233,330,240); // 1 line(330,240,337,240); // right hori line(320,240,313,240); //left hori line(313,240,318,247); // left horiz to right line(337,240,332,247); // right horiz to left / line(332,247,334,253); // left / to right line(318,247,316,253); // right to left / line(316,253,325,247); line(334,253,325,247);*/ // getch(); } } ya(int i) { if(i==120) { delay(1); setcolor(4); // delay(800); outtextxy(300+i,230,"Y"); }setcolor(14); delay(1); outtextxy(420,230,"Y"); //440 } r(int i) { if(i==90) { setcolor(2); delay(1); outtextxy(300+i,230,"R"); }setcolor(14); delay(1); outtextxy(390,230,"R"); // 420 } e1(int i) { if(i==60) { setcolor(2); delay(1); outtextxy(300+i,230,"E"); }setcolor(14); delay(1); outtextxy(360,230,"E"); //400 } h1(int i) { if(i==30) { setcolor(2); delay(1); outtextxy(300+i,230,"H"); }setcolor(14); delay(1); outtextxy(330,230,"H"); //380 } c1(int i) { if(i==60) { setcolor(2); delay(1); outtextxy(300+i-i,230,"C"); }setcolor(14); delay(1); outtextxy(300,230,"C"); //360 } r1(int i) { if(i==40) { setcolor(2); delay(1); outtextxy(300+i-70,230,"R"); }setcolor(14); delay(1); outtextxy(270,230,"R"); // 340 } a1(int i) { if(i==20) { setcolor(2); delay(1); outtextxy(300+i-80,230,"A"); }setcolor(14); delay(1); outtextxy(240,230,"A"); //320 } star(x,y) { delay(80); line(x,y,x+5,y-7); // /1 x=320, y=240 line(x+5,y-7,x+10,y); // 1 line(x+10,y,x+17,y); // right hori line(x,y,x-7,y); //left hori line(x-7,y,x-2,y+7); // left horiz to right line(x+17,y,x+12,y+7); // right horiz to left / line(x+12,y+7,x+14,y+13); // left / to right line(x-2,y+7,x-4,y+13); // right to left / line(x-4,y+13,x+5,y+7); line(x+14,y+13,x+5,y+7); } front() { int gm=0,gd=DETECT,i,j,k,jk,gh; initgraph(&gd,&gm," "); setcolor(MAGENTA); rectangle(10,10,639,469); rectangle(12,12,637,467); for(i=12;i<=627;i+=12) { setcolor(YELLOW); line(i,12,i,467); //clearviewport(); for(j=15;j<=464;j+=5) ellipse(i+6,j,-180,0,6,4); } for(i=3;i<=452;i+=5) { for(j=15;j<=627;j+=3) {setcolor(0); ellipse(j,467-i,-180,0,3,4); }delay(40); setcolor(BLACK); for(k=1;k<=5;k++) { line(12,467-i+k,637,467-i+k); } //setcolor(25); setcolor(GREEN+MAGENTA+WHITE+BLUE+YELLOW); rectangle(10,10,639,469); rectangle(12,12,637,467); } setcolor(2); rectangle(290,370,350,380); rectangle(292,372,348,378); gh=292; //gh<=388; for(j=1;j<=56;j+=1) { /* for(i=24;i<=627;i+=12) {setcolor(i); circle(i,23,3); delay(1); } */ jk=20; for(i=24;i<=627;i+=12) {setcolor(random(15)); circle(i,23,3); sound(200-i); delay(1); nosound(); setcolor(YELLOW); rectangle(gh,372,gh,378); //rectangle(282,362,358,388);} jk+=40; if(jk>=880) { jk=440;} } gh=gh+1; nosound(); } //printf("sdfs"); sta(); sleep(.1); //closegraph(); } gaover() { int gm=0,gd=DETECT,i,j; initgraph(&gd,&gm," "); for(i=1;i<=51;i+=4) { setcolor(i); sound(400-i); outtextxy(260,340,"GAME OVER"); if(i==49) { setcolor(YELLOW); outtextxy(260,340,"GAME OVER"); } nosound(); go(0,60,20,80,random(15),random(15)); delay(3); go(400,460,420,480,random(15),random(15)); } //getch(); } go(int sy1,int ey1,int sy2,int ey2,int k,int h) { int i,j; for(j=sy1;j<=ey1;j+=40) //120 { for(i=0;i<=640;i+=40) { setcolor(k); rectangle(i,1+j,20+i,21+j); setfillstyle(SOLID_FILL,k); floodfill(10+i,10+j,k); setcolor(h); rectangle(20+i,1+j,40+i,21+j); setfillstyle(SOLID_FILL,h); floodfill(25+i,10+j,h); } } for(j=sy2;j<=ey2;j+=40) { for(i=0;i<=640;i+=40) { setcolor(h); rectangle(i,1+j,20+i,21+j); setfillstyle(SOLID_FILL,h); floodfill(10+i,10+j,h); setcolor(k); rectangle(20+i,1+j,40+i,21+j); setfillstyle(SOLID_FILL,k); floodfill(25+i,10+j,k); } } // } select(int scor,int p,int q) { switch(scor) { case 0: outtextxy(530+p,50+q,"0"); break; case 10: outtextxy(530+p,50+q,"10"); break; case 20: outtextxy(530+p,50+q,"20"); break; case 30: outtextxy(530+p,50+q,"30"); break; case 40: outtextxy(530+p,50+q,"40"); break; case 50: outtextxy(530+p,50+q,"50"); break; case 60: outtextxy(530+p,50+q,"60"); break; case 70: outtextxy(530+p,50+q,"70"); break; case 80: outtextxy(530+p,50+q,"80"); break; case 90: outtextxy(530+p,50+q,"90"); break; case 100: outtextxy(530+p,50+q,"100"); break; case 110: outtextxy(530+p,50+q,"110"); break; case 120: outtextxy(530+p,50+q,"120"); break; case 130: outtextxy(530+p,50+q,"130"); break; case 140: outtextxy(530+p,50+q,"140"); break; case 150: outtextxy(530+p,50+q,"150"); break; case 160: outtextxy(530+p,50+q,"160"); break; case 170: outtextxy(530+p,50+q,"170"); break; case 180: outtextxy(530+p,50+q,"180"); break; case 190: outtextxy(530+p,50+q,"190"); break; case 200: outtextxy(530+p,50+q,"200"); break; case 210: outtextxy(530+p,50+q,"210"); break; case 220: outtextxy(530+p,50+q,"220"); break; case 230: outtextxy(530+p,50+q,"230"); break; case 240: outtextxy(530+p,50+q,"240"); break; case 250: outtextxy(530+p,50+q,"250"); break; case 260: outtextxy(530+p,50+q,"260"); break; case 270: outtextxy(530+p,50+q,"270"); break; case 280: outtextxy(530+p,50+q,"280"); break; case 290: outtextxy(530+p,50+q,"290"); break; case 300: outtextxy(530+p,50+q,"300"); break; case 310: outtextxy(530+p,50+q,"310"); break; case 320: outtextxy(530+p,50+q,"320"); break; case 330: outtextxy(530+p,50+q,"330"); break; case 340: outtextxy(530+p,50+q,"340"); break; case 350: outtextxy(530+p,50+q,"350"); break; case 360: outtextxy(530+p,50+q,"360"); break; } } flower(int i,int j) { setcolor(14); circle(320+i,240+j,10); setfillstyle(SOLID_FILL,RED); floodfill(323+i,241+j,14); //1 setcolor(14); //floodfill(316,223,13); ellipse(310+i,220+j,90,-90,6,12); ellipse(330+i,220+j,-90,90,6,12); ellipse(320+i,207+j,180,0,8,2); //2 ellipse(310+i,260+j,90,-90,6,12); ellipse(330+i,260+j,-90,90,6,12); ellipse(320+i,273+j,0,180,8,2); //3 ellipse(298+i,248+j,180,0,12,6); ellipse(298+i,233+j,0,180,12,6); ellipse(286+i,240+j,-90,90,2,8); //4 ellipse(342+i,247+j,180,0,12,6); ellipse(342+i,233+j,0,180,12,6); ellipse(354+i,240+j,90,-90,2,8); } finalwindow() { for(k=-285;k<=320;k+=70) { flower(k,-205); flower(k,+180); //clearviewport(); delay(100); } for(k=-140;k<=180;k+=40) { flower(-285,k); flower(276,k); //clearviewport(); delay(100); } setcolor(2); sleep(4); }

This library function is declared in graphics.h and used to draw a circle; it takes centre point coordinates and radius. Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle. Where, (x, y) is center of the circle. 'radius' is the Radius of the circle.

The header file graphics.h contains setfillstyle() function which sets the current fill pattern and fill color. Current fill pattern and fill color is used to fill the area. setfillstyle sets the current fill pattern and fill color. To set a user-defined fill pattern, do not give a pattern of 12 (USER_FILL) to setfillstyle; instead, call setfillpattern.

In the C programming language, there is an option to create an arc of a circle of a given radius with a given center coordinates and degree of the arc. The arc() function is used to create an arc. This arc function is included in graphics.h library in C which contains methods that can draw figures on the output screen. The function to make an arc(), accepts five parameters for x, y co-ordinate, starting angle, end angle and radius. This will make the arc will all the values are fine. The Example below takes care of all these things as it have four arcs implemented.

Clears the current viewport. clearviewport() function will erase the drawing done on the view port only and not the whole screen. Cleardevice is the function used to clear the whole screen with the background color. clearviewport() clears the current view port and resets the current position to (0, 0), relative to the current view port.

line() is a library function of graphics.c in c programming language which is used to draw a line from two coordinates. line() function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.

The nosound() function in C language is used to stop the sound played by sound() function. nosound() function is simply silent the system. Sound function produces the sound of a specified frequency and nosound function turn off the PC speaker.

An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming. These operators are used to perform logical operations and used with conditional statements like C if-else statements.

rectangle() is used to draw a rectangle. Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner.

Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, startangle is the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively. Making a circle and an ellipse in C can be done easily. How to do is, first initialize a graph with two parameters and a path to the "bgi" folder in your system.

outtextxy displays a text string in the viewport at the given position (x, y), using the current justification settings and the current font, direction, and size. To maintain code compatibility when using several fonts, use textwidth and textheight to determine the dimensions of the string. If a string is printed with the default font using outtext or outtextxy, any part of the string that extends outside the current viewport is truncated. outtextxy is for use in graphics mode; it will not work in text mode.

While loop is also known as a pre-tested loop. In general, a while loop allows a part of the code to be executed multiple times depending upon a given boolean condition. It can be viewed as a repeating if statement. The while loop is mostly used in the case where the number of iterations is not known in advance. The while loop evaluates the test expression inside the parentheses (). If test expression is true, statements inside the body of while loop are executed. Then, test expression is evaluated again. The process goes on until test expression is evaluated to false. If test expression is false, the loop terminates.

The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness of the condition. Here, we must notice that if and else block cannot be executed simiulteneously. Using if-else statement is always preferable since it always invokes an otherwise case with every if condition.

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. printf format string refers to a control parameter used by a class of functions in the input/output libraries of C programming language. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data (such as a number) to characters. "printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (parsing). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible template engines or parsers,

Switch statement in C tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier. The value provided by the user is compared with all the cases inside the switch block until the match is found. If a case match is NOT found, then the default statement is executed, and the control goes out of the switch block.

Delay function is used to suspend execution of a program for a particular time. delay() function requires a parameter which should be a number, defining the milliseconds for the delay. To use delay function in your program you should include the "dos.h" header file which is not a part of standard C library. Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds).

getarccoords fills in the arccoordstype structure pointed to by arccoords with information about the last call to arc. The header file graphics.h contains getarccoords() function which is used to get coordinates of arc which is drawn most recently. The members of this structure are used to specify the center point (x,y), the starting position (xstart, ystart), and the ending position (xend, yend) of the arc. These values are useful if you need to make a line meet at the end of an arc.

Settextstyle function is used to change the way in which text appears, using it we can modify the size of text, change direction of text and change the font of text. settextstyle sets the text font, the direction in which text is displayed, and the size of the characters. A call to settextstyle affects all text output by outtext and outtextxy.

initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode. You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached video adapter at run time and pick the corresponding driver.

The for loop is used in the case where we need to execute some part of the code until the given condition is satisfied. The for loop is also called as a per-tested loop. It is better to use for loop if the number of iteration is known in advance. The for-loop statement is a very specialized while loop, which increases the readability of a program. It is frequently used to traverse the data structures like the array and linked list.

A goto statement in C programming language provides an unconditional jump from the 'goto' to a labeled statement in the same function. The goto statement is known as jump statement in C. As the name suggests, goto is used to transfer the program control to a predefined label. The goto statment can be used to repeat some part of the code for a particular condition. It can also be used to break the multiple loops which can't be done by using a single break statement.

The break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops.

setcolor() function is used to set the foreground color in graphics mode. After resetting the foreground color you will get the text or any other shape which you want to draw in that color. setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively.

The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program.

The if...else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities. The if...else ladder allows you to check between multiple test expressions and execute different statements. In C/C++ if-else-if ladder helps user decide from among multiple options. The C/C++ if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the C else-if ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.

In C, the "main" function is treated the same as every function, it has a return type (and in some cases accepts inputs via parameters). The only difference is that the main function is "called" by the operating system when the user runs the program. Thus the main function is always the first code executed when a program starts. main() function is a user defined, body of the function is defined by the programmer or we can say main() is programmer/user implemented function, whose prototype is predefined in the compiler. Hence we can say that main() in c programming is user defined as well as predefined because it's prototype is predefined. main() is a system (compiler) declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.

Our system can create various sounds on different frequencies. The sound() is very useful as it can create very nice music with the help of programming and our user can enjoy music during working in out the program. Sound function produces the sound of a specified frequency. Used for adding music to a C program, try to use some random values in loop, vary delay and enjoy.

A union is a special data type available in C that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose. To define a union, you must use the union statement in the same way as you did while defining a structure. The union statement defines a new data type with more than one member for your program. The format of the union statement is as follows:

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:

Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language: Simple assignment operator. Assigns values from right side operands to left side operand. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand.

floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled otherwise outside will be filled,border specifies the color of boundary of area. To change fill pattern and fill color use setfillstyle. floodfill fills an enclosed area on bitmap devices. (x,y) is a "seed point" within the enclosed area to be filled. The area bounded by the color border is flooded with the current fill pattern and fill color.

The header file graphics.h contains closegraph() function which closes the graphics mode, deallocates all memory allocated by graphics system and restores the screen to the mode it was in before you called initgraph. closegraph() function is used to re-enter in the text mode and exit from the graphics mode. If you want to use both text mode and graphics mode in the program then you have to use both initgraph() and closegraph() function in the program.

setbkcolor() function is used to set the background color in graphics mode. The default background color is black and default drawing color as we know is white. setbkcolor() function takes only one argument it would be either the name of color defined in graphics.h header file or number associated with those colors. If we write setbkcolor(yellow) it changes the background color in Green.

C programming language provides sleep() function in order to wait for a current thread for a specified time. slepp() function will sleep given thread specified time for the current executable. Of course, the CPU and other processes will run without a problem. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to the scheduling of other activity by the system. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer




Code compare function for qsort. Add ONE element to the array. Allocate memory for ONE 'struct node'. Copy the data into the new element ( structure ). Qsort array of...

If a number remains same, even if we reverse its digits then number is Palindrome number. So 10201 is a Palindrome Number because it remains same if we reverse its digits. C codes

C Programing code to perform functions of a calculator: factorial, addition, subtraction, multiplication, division, squares. Sum of the input numbers. The difference between the

C language programming code to calculate sum of array. This program should give an insight of how to parse (read) array. We shall use a loop and sum up all values of the array.

C Program uses recursive function & reverses the nodes in a Linked list and displays the list. Linked list is an ordered set of data elements, each 'containing a link' to its successor. This C



In this c program code, a structure Distance is defined. The structure has two members inch (a float) and feet (an integer). Two variables (distance1 and distance2) are created which...

This program takes the 3 numbers & finds the biggest among all. Take the three numbers as input and Check the First number if it Greater than other two. Repeat the step 2 for other 2