Skip to main content

Posts

Showing posts with the label C Programming

Basic Building Blocks Of The C Programming | VCMIT

Basic Building Blocks Of The C Programming You have seen the basic structure of a C program, so it will be easy to understand other basic building blocks of the C programming language. Tokens in C A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens − printf("Hello, World! \n"); The individual tokens are − printf (    "Hello, World! \n" ) ; Semicolons In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. Given below are two different statements − printf("Hello, World! \n"); return 0; Comments Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below − /* my first program in C */ You cannot have comments withi...

Hello World Example In C Programming | VCMIT

Hello World Example A C program basically consists of the following parts − Preprocessor Commands Functions Variables Statements & Expressions Comments Let us look at a simple code that would print the words "Hello World" − INPUT #include <stdio.h> void main {    /* my first program in C */    printf("Hello, World! \n");    getch; } Let us take a look at the various parts of the above program − The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation. The next line int main() is the main function where the program execution begins. The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen. The next line...

Applications Of C Programming | Audience & Prerequisites | VCMIT

Applications of C Programming C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language. Some examples of the use of C are - Operating Systems Language Compilers Assemblers Text Editors Print Spoolers Network Drivers Modern Programs Databases Language Interpreters Utilities Audience This tutorial is designed for software programmers with a need to understand the C programming language starting from scratch. This C tutorial will give you enough understanding on C programming language from where you can take yourself to higher level of expertise. Prerequisites Before proceeding with this tutorial, you should have a basic understanding of Computer Programming terminologies. A basic understanding of any of the programming languages will help you in understanding the C programming concepts and move fast...

What Is C Programming? | Why To Learn C Programming | VCMIT

What Is C Programming C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers. Why to Learn C Programming? C programming language is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. I will list down some of the key advantages of learning C Programming: Easy to learn Structured language It produces efficient programs It can handle low-level activities It can be compiled on a variety of computer platforms Facts about C C was invented to write an operating system called UNIX. C is a successor of B language which was introduced aroun...

Draw The Moving Car On The Screen Program In C | VCMIT

The Moving Car Program In C  INPUT #include <stdio.h> #include <graphics.h> #include <conio.h> #include <dos.h> int main() { int gd = DETECT, gm; int i, maxx, midy; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); maxx = getmaxx(); midy = getmaxy()/2; for (i=0; i < maxx-150; i=i+5) { cleardevice(); setcolor(WHITE); line(0, midy + 37, maxx, midy + 37); setcolor(YELLOW); setfillstyle(SOLID_FILL, RED); line(i, midy + 23, i, midy); line(i, midy, 40 + i, midy - 20); line(40 + i, midy - 20, 80 + i, midy - 20); line(80 + i, midy - 20, 100 + i, midy); line(100 + i, midy, 120 + i, midy); line(120 + i, midy, 120 + i, midy + 23); line(0 + i, midy + 23, 18 + i, midy + 23); arc(30 + i, midy + 23, 0, 180, 12); line(42 + i, midy + 23, 78 + i, midy + 23); arc(90 + i, midy + 23, 0, 180, 12); line(102 + i, midy + 23, 120 + i, midy + 23); line(28 + i, midy, 43 + i, midy - 15); line(43 + i, midy - 15, 57 + i, midy - 15); line(57 + i, midy - 15, 57 + i, midy); line(57 +...

Develop The Program For The DDA Line Drawing Algorithm In C | VCMIT

The DDA Line Drawing Algorithm  INPUT #include <graphics.h> #include <stdio.h> #include <math.h> #include <dos.h> void main( ) { float x,y,x1,y1,x2,y2,dx,dy,step; int i,gd=DETECT,gm; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("Enter the value of x1 and y1 : "); scanf("%f%f",&x1,&y1); printf("Enter the value of x2 and y2: "); scanf("%f%f",&x2,&y2); dx=abs(x2-x1); dy=abs(y2-y1); if(dx>=dy) step=dx; else step=dy; dx=dx/step; dy=dy/step; x=x1; y=y1; i=1; while(i<=step) { putpixel(x,y,5); x=x+dx; y=y+dy; i=i+1; delay(100); } getch(); closegraph(); } OUTPUT

Bresenham’s Line Drawing Algorithm Program In C | VCMIT

Bresenham’s Line Drawing Algorithm Program In C INPUT #include<stdio.h> #include<graphics.h> void drawline(int x0, int y0, int x1, int y1) { int dx, dy, p, x, y; dx=x1-x0; dy=y1-y0; x=x0; y=y0; p=2*dy-dx; while(x<x1) { if(p>=0) { putpixel(x,y,7); y=y+1; p=p+2*dy-2*dx; } else { putpixel(x,y,7); p=p+2*dy; } x=x+1; } } int main() { int gdriver=DETECT, gmode, error, x0, y0, x1, y1; initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi"); printf("Enter co-ordinates of first point: "); scanf("%d%d", &x0, &y0); printf("Enter co-ordinates of second point: "); scanf("%d%d", &x1, &y1); drawline(x0, y0, x1, y1); getch(); } OUTPUT

Create House Like Structure Perform Operations Program In C | VCMIT

Program to create a house like figure and perform the following operations.  Scaling about the origin followed by translation.  Scaling with reference to an arbitrary point. Reflect about the line y = mx + c. INPUT #include <stdio.h> #include <graphics.h> #include <stdlib.h> #include <math.h> #include <conio.h> void reset (int h[][2]) { int val[9][2] = { { 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 }, { 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 } }; int i; for (i=0; i<9; i++) { h[i][0] = val[i][0]-50; h[i][1] = val[i][1]-50; } } void draw (int h[][2]) { int i; setlinestyle (DOTTED_LINE, 0, 1); line (320, 0, 320, 480); line (0, 240, 640, 240); setlinestyle (SOLID_LINE, 0, 1); for (i=0; i<8; i++) line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]); line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]); } void rotate (int h[][2], float angle) { int i; for (i=0; i<9; i++) { int xnew, ynew; xnew = h[i][0] * cos (angl...

Perform 2D Rotation On A Given Object Program In C | VCMIT

2D Rotation On A Given Object Program INPUT #include<stdio.h> #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gdriver,&gmode,"C//TurboC3//BGI"); int x1,y1,x2,y2 ; float b1,b2; float t,deg; printf(“Enter the coordinates of Line: ”); scanf(“%d%d%d%d”,&x1,&y1,&x2,&y2); setcolor(6); line(x1,y1,x2,y2); getch(); //cleardevice(); printf(“Enter the angle of rotation: “); scanf(“%f”,&deg); t=(22*deg)/(180*7); b1=abs((x2*cos(t))-(y2*sin(t))); b2=abs((x2*sin(t))+(y2*cos(t))); line(x1,y1,b1,b2); getch(); closegraph(); } OUTPUT

Perform Smiling Face Animation Using Graphic Functions Program In C | VCMIT

Smiling Face Animation Program INPUT #include<graphics.h> #include<conio.h> #include<stdlib.h> main() { int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75; void *p; initgraph(&gd,&gm,"C:\\TC\\BGI"); setcolor(YELLOW); circle(50,100,25); setfillstyle(SOLID_FILL,YELLOW); floodfill(50,100,YELLOW); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); fillellipse(44,85,2,6); fillellipse(56,85,2,6); ellipse(50,100,205,335,20,9); ellipse(50,100,205,335,20,10); ellipse(50,100,205,335,20,11); area = imagesize(left, top, left + 50, top + 50); p = malloc(area); setcolor(WHITE); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); outtextxy(155,451,"Smiling Face Animation"); setcolor(BLUE); rectangle(0,0,639,449); while(!kbhit()) { temp1 = 1 + random ( 588 ); temp2 = 1 + random ( 380 ); getimage(left, top, left + 50, top + 50, p); putimage(left, top, p, XOR_PUT); putimage(temp1 , temp2, p, XOR_PUT); delay(100); left = temp1; top = temp2; } getch(); closegra...

Draw A Simple Hut On The Screen Program In C | VCMIT

A Simple Hut On The Screen INPUT #include<graphics.h> #include<conio.h> int main(){ int gd = DETECT,gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); setcolor(WHITE); rectangle(150,180,250,300); rectangle(250,180,420,300); rectangle(180,250,220,300); line(200,100,150,180); line(200,100,250,180); line(200,100,370,100); line(370,100,420,180); setfillstyle(SOLID_FILL, BROWN); floodfill(152, 182, WHITE); floodfill(252, 182, WHITE); setfillstyle(SLASH_FILL, BLUE); floodfill(182, 252, WHITE); setfillstyle(HATCH_FILL, GREEN); floodfill(200, 105, WHITE); floodfill(210, 105, WHITE); getch(); closegraph(); return 0; } OUTPUT

Write A Program To Fill A Circle Using Flood Fill Algorithm | VCMIT

Fill A Circle Using Flood Fill Algorithm INPUT #include<stdio.h> #include<conio.h> #include<graphics.h> void floodFill(int, int, int, int); int midx=319, midy=239; void main() { int gdriver=DETECT, gmode, x,y,r; initgraph(&gdriver, &gmode, "C:\\TURBOCS3\\BGI"); cleardevice(); printf("Enter the Center of circle (X,Y) : "); scanf("%d %d",&x,&y); printf("Enter the Radius of circle R : "); scanf("%d",&r); circle(midx+x,midy-y,r); getch(); floodFill(midx+x,midy-y,13,0); getch(); closegraph(); } void floodFill(int x, int y, int fill, int old) { if(getpixel(x,y) == old) { putpixel(x,y,fill); delay(5); floodFill(x+1,y,fill,old); floodFill(x-1,y,fill,old); floodFill(x,y+1,fill,old); floodFill(x,y-1,fill,old); } } OUTPUT

Write A Program To Implement Liang - Barsky Line Clipping Algorithm | VCMIT

Write A Program To Implement Liang - Barsky Line Clipping Algorithm INPUT #include<stdio.h> #include<graphics.h> #include<math.h> #include<dos.h> void main() { int i,gd=DETECT,gm; int x1,y1,x2,y2,xmin,xmax,ymin,ymax,xx1,xx2,yy1,yy2,dx,dy; float t1,t2,p[4],q[4],temp; x1=120; y1=120; x2=300; y2=300; xmin=100; ymin=100; xmax=250; ymax=250; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); rectangle(xmin,ymin,xmax,ymax); dx=x2-x1; dy=y2-y1; p[0]=-dx; p[1]=dx; p[2]=-dy; p[3]=dy; q[0]=x1-xmin; q[1]=xmax-x1; q[2]=y1-ymin; q[3]=ymax-y1; for(i=0;i<4;i++) { if(p[i]==0) { printf("line is parallel to one of the clipping boundary"); if(q[i]>=0) { if(i<2) { if(y1<ymin) { y1=ymin; } if(y2>ymax) { y2=ymax; } line(x1,y1,x2,y2); } if(i>1) { if(x1<xmin) { x1=xmin; } if(x2>xmax) { x2=xmax; } line(x1,y1,x2,y2); } } } } t1=0; t2=1; for(i=0;i<4;i++) { temp=q[i]/p[i]; if(p[i]<0) { if(t1<=temp) t1=temp; } else { if(t2>temp) t2=temp; }...

Draw The Walking Man On The Screen Program In C | BGI | VCMIT

Draw The Walking Man On The Screen Program In C INPUT #include<stdio.h> #include<graphics.h> #define ScreenWidth getmaxx() #define ScreenHeight getmaxy() #define GroundY ScreenHeight*0.75 int ldaisp=0; void DrawManWithUmbrella(int a,int ldaisp) { //Draw Umbrella pieslice(a+20,GroundY-120,0,180,40); line(a+20,GroundY-120,a+20,GroundY-70); //Draw head circle(a,GroundY-90,10); line(a,GroundY-80,a,GroundY-30); //Draw hand line(a,GroundY-70,a+10,GroundY-60); line(a,GroundY-65,a+10,GroundY-55); line(a+10,GroundY-60,a+20,GroundY-70); line(a+10,GroundY-55,a+20,GroundY-70); //Draw legs line(a,GroundY-30,a+ldaisp,GroundY); line(a,GroundY-30,a-ldaisp,GroundY); } void Rain(int a) { int i,rx,ry; for(i=0;i<400;i++) { rx=rand() % ScreenWidth; ry=rand() % ScreenHeight; if(ry<GroundY-4) { if(ry<GroundY-120 || (ry>GroundY-120 && (rx<a-20 || rx>a+60))) line(rx,ry,rx+0.5,ry+4); } } } void main() { int gd=DETECT,gm,a=0; initgraph(&gd,&gm,"C:\\TC\\BGI"...

Drawing Different Shapes Program In C | BGI | VCMIT

Drawing Different Shapes Program In C INPUT #include<graphics.h> #include<conio.h> main() {    int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;    initgraph(&gd, &gm, "C:\\TC\\BGI");    rectangle(left, top, right, bottom);    circle(x, y, radius);    bar(left + 300, top, right + 300, bottom);    line(left - 10, top + 150, left + 410, top + 150);    ellipse(x, y + 200, 0, 360, 100, 50);    outtextxy(left + 100, top + 325, "My first C graphics program");    getch();    closegraph();    return 0; } OUTPUT

Moving Fish Program In C| BGI | VCMIT

Moving Fish Program In C IINPUT #include<stdlib.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<ctype.h> void main() {         int gd=DETECT,gm;         int xincr=0,newy=0,yincr=5;         initgraph(&gd,&gm," ");         cleardevice();         while(!kbhit())         {                 ellipse(520-xincr,200,30,330,90,30);                 circle(450-xincr,193,3);                 line(430-xincr,200,450-xincr,200);                 line(597-xincr,185,630-xincr,170);                 line(597-xincr,215,630-xincr,227);                 line(630-xincr,170,630-xincr,227);     ...