Powered by Blogger.

The


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 within comments and they do not occur within a string or character literals.

Identifiers

A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9).

C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers −

mohd zara abc move_name a_123
myname50 _temp j a23b9 retVal

Keywords

The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.


Whitespace in C

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.

Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement −

int age;

there must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement −

fruit = apples + oranges; // get the total fruit

no whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish to increase readability.




Share
Tweet
Pin
Share
No Comments
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 return 0; terminates the main() function and returns the value 0.


Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −


  • Open a text editor and add the above-mentioned code.
  • Save the file as hello.c
  • Open a command prompt and go to the directory where you have saved the file.
  • Type gcc hello.c and press enter to compile your code.
  • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file.
  • Now, type a.out to execute your program.
  • You will see the output "Hello World" printed on the screen.


OUTPUT

Hello, World

Share
Tweet
Pin
Share
No Comments

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 on the learning track.



Share
Tweet
Pin
Share
No Comments
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 around the early 1970s.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C.
  • Today C is the most widely used and popular System Programming Language.
  • Most of the state-of-the-art software have been implemented using C.
  • Today's most popular Linux OS and RDBMS MySQL have been written in C.


Share
Tweet
Pin
Share
No Comments
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 + i, midy, 28 + i, midy);
line(62 + i, midy - 15, 77 + i, midy - 15);
line(77 + i, midy - 15, 92 + i, midy);
line(92 + i, midy, 62 + i, midy);
line(62 + i, midy, 62 + i, midy - 15);
floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);

circle(30 + i, midy + 25, 9);
circle(90 + i, midy + 25, 9);
floodfill(30 + i, midy + 25, BLUE);
floodfill(90 + i, midy + 25, BLUE);
/* Add delay of 0.1 milli seconds */
delay(100);
}
getch();
closegraph();
return 0;
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
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



Share
Tweet
Pin
Share
No Comments
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



Share
Tweet
Pin
Share
No Comments
Program to create a house like figure and perform the following operations.
  1.  Scaling about the origin followed by translation.
  2.  Scaling with reference to an arbitrary point.
  3. 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 (angle) - h[i][1] * sin (angle);
ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
h[i][0] = xnew; h[i][1] = ynew;
}
}
void scale (int h[][2], int sx, int sy)
{
int i;
for (i=0; i<9; i++)
{
h[i][0] *= sx;
h[i][1] *= sy;
}
}
void translate (int h[][2], int dx, int dy)
{
int i;
for (i=0; i<9; i++)
{
h[i][0] += dx;
h[i][1] += dy;
}
}
void reflect (int h[][2], int m, int c)
{
int i;
float angle;
for (i=0; i<9; i++)
h[i][1] -= c;
angle = M_PI/2 - atan (m);
rotate (h, angle);
for (i=0; i<9; i++)
h[i][0] = -h[i][0];
angle = -angle;
rotate (h, angle);
for (i=0; i<9; i++)
h[i][1] += c;
}

void ini()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\\bgi");
}
void dini()
{
getch();
closegraph();
}
void main()
{

int h[9][2],sx,sy,x,y,m,c,choice;
do
{
clrscr();
printf("1. Scaling about the origin.\n");
printf("2. Scaling about an arbitrary point.\n");
printf("3. Reflection about the line y = mx + c.\n");
printf("4. Exit\n");
printf("Enter the choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf ("Enter the x- and y-scaling factors: ");
scanf ("%d%d", &sx, &sy);
ini();
reset (h);
draw (h);getch();
scale (h, sx, sy);
cleardevice();
draw (h);
dini();
break;

case 2: printf ("Enter the x- and y-scaling factors: ");
scanf ("%d%d", &sx, &sy);
printf ("Enter the x- and y-coordinates of the point: ");
scanf ("%d%d", &x, &y);
ini();
reset (h);
translate (h, x, y);// Go to arbitrary point
draw(h); getch();//Show its arbitrary position
cleardevice();
translate(h,-x,-y);//Take it back to origin
draw(h);
getch();
cleardevice();
scale (h, sx, sy);//Now Scale it
draw(h);
getch();
translate (h, x, y);//Back to Arbitrary point
cleardevice();
draw (h);
putpixel (320+x, 240-y, WHITE);
dini();
break;
case 3: printf ("Enter the values of m and c: ");
scanf ("%d%d", &m, &c);
ini();
reset (h);
draw (h); getch();
reflect (h, m, c);
cleardevice();
draw (h);
dini();
break;
case 4: exit(0);
}
}while(choice!=4);
}

OUTPUT



1. Scaling about the origin followed by translation.




2. Scaling with reference to an arbitrary point.



3. Reflect about the line y = mx + c.


Share
Tweet
Pin
Share
No Comments
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


Share
Tweet
Pin
Share
No Comments
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();
closegraph();
return 0;
}

OUTPUT


Share
Tweet
Pin
Share
No Comments
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



Share
Tweet
Pin
Share
No Comments
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


Share
Tweet
Pin
Share
No Comments
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;
}
}
if(t1<t2)
{
xx1 = x1 + t1 * p[1];
xx2 = x1 + t2 * p[1];
yy1 = y1 + t1 * p[3];
yy2 = y1 + t2 * p[3];
line(xx1,yy1,xx2,yy2);
}
delay(50000);
closegraph();
getch();
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
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");

while(!kbhit())
{
//Draw Ground
line(0,GroundY,ScreenWidth,GroundY);
Rain(a);
ldaisp=(ldaisp+2)%20;
DrawManWithUmbrella(a,ldaisp);
delay(40);
cleardevice();
a=(a+2)%ScreenWidth;
}
getch();
}

OUTPUT





Share
Tweet
Pin
Share
No Comments
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




Share
Tweet
Pin
Share
No Comments
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);
                line(597-xincr,200,630-xincr,200);
                line(597-xincr,192,630-xincr,187);
                line(597-xincr,207,630-xincr,213);
                line(500-xincr,190,540-xincr,150+newy);
                line(530-xincr,190,540-xincr,150+newy);
                if(xincr>=500)
                        xincr=0;
                if(newy>=82)
                        yincr=-5;
                xincr=xincr+5;
                if(newy<=0)
                        yincr=5;
                newy=newy+yincr;
                delay(50);
                cleardevice();
        }
        cleardevice();
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
Turtle Python Logo Program


INPUT

import turtle

l1 = [[0.0, -238.0], [92.6, -219.3], [168.3, -168.3], [219.3, -92.6], [238.0, 0.0], [219.3, 92.6], [168.3, 168.3], [92.6, 219.3], [0.0, 238.0], [-92.6, 219.3], [-168.3, 168.3], [-219.3, 92.6], [-238.0, 0.0], [-219.3, -92.6], [-168.3, -168.3], [-92.6, -219.3], [0.0, -238.0], [0.0, -256.0], [-99.6, -235.9], [-181.0, -181.0], [-235.9, -99.6], [-256.0, 0.0], [-235.9, 99.6], [-181.0, 181.0], [-99.6, 235.9], [0.0, 256.0], [99.6, 235.9], [181.0, 181.0], [235.9, 99.6], [256.0, 0.0], [235.9, -99.6], [181.0, -181.0], [99.6, -235.9], [0.0, -256.0], [0.0, -256.0], [0.0, -256.0], [0.0, -256.0], [0.0, -256.0], [0.0, -256.0]]
l2 = [[-83.1, 17.3], [-64.3, 16.4], [-13.81, 32.1], [3.2, 70.7], [-18.9, 115.4], [-70.5, 130.1], [-76.5, 129.9], [-82.7, 129.3], [-82.7, 128.7], [-82.7, 128.1], [-93.8, 128.1], [-104.9, 128.1], [-104.9, 127.5], [-104.9, -128.6], [-82.7, -126.9], [-104.9, -128.6], [-104.8, 20.4]]
l3 = [[-82.7, 110.4], [-75.9, 111.0], [-69.7, 111.2], [-34.8, 101.6], [-20.8, 73.4], [-32.0, 46.1], [-63.8, 35.8], [-72.2, 36.1], [-82.7, 37.2], [-82.7, 38.3], [-82.7, -126.9], [-82.7, 110.4]]
l4 = [[81.7, -76.9], [58.9, -114.2], [25.0, -134.9], [21.13, -125.4], [17.2, -115.9], [42.5, -101.7], [58.0, -79.0], [33.8, -13.4], [9.63, 52.2], [22.3, 52.2], [35.0, 52.2], [52.6, -1.8], [70.2, -55.8], [87.9, -1.8], [105.6, 52.2], [117.6, 52.2], [129.6, 52.2], [105.7, -12.3], [81.7, -76.9], [81.7, -76.9]]
l5 = [[220.5, 96], [168.9, 96], [117.3, 96], [90.5, 107.1], [79.3, 134], [79.3, 180.7], [79.3, 227.5], [88.3, 227.5], [97.3, 227.5], [97.3, 180.7], [97.3, 134], [103.2, 119.9], [117.3, 114], [168.9, 114], [220.5, 114], [220.5, 105], [220.5, 96]]


def drawseg(l):
    turtle.pu()
    turtle.goto(l[0][0], l[0][1])
    turtle.pd()
    for a, b in l[1:]:
        turtle.goto(a, b)


drawseg(l1)
drawseg(l2)
drawseg(l3)
drawseg(l4)
drawseg(l5)
turtle.mainloop()


OUTPUT



Share
Tweet
Pin
Share
No Comments
Python TKinter Theme Program | TKinter | WaoFamHub



INPUT

from tkinter import Tk, Label, Button, Entry, X

import tkinter
from tkinter import ttk
from tkinter import messagebox


class Root(Tk):
    def __init__(self):
        super().__init__()

        for x in [ttk.Label, ttk.Button, ttk.Entry, ttk.Checkbutton, ttk.Radiobutton]:
            x(self, text='Some ' + x.__name__).pack(fill=X)
        pb = ttk.Progressbar(self, length=100)
        pb.pack(fill=X)
        pb.step(33)

        ttk.Label(self, text='Select theme:').pack(pady=[50, 10])

        self.style = ttk.Style()
        self.combo = ttk.Combobox(self, values=self.style.theme_names())
        self.combo.pack(pady=[0, 10])
        button = ttk.Button(self, text='Apply')
        button['command'] = self.change_theme
        button.pack(pady=10)

    def change_theme(self):
        content = self.combo.get()
        try:
            self.style.theme_use(content)
        except:
            print("Failed to set theme " + content)


root = Root()
root.mainloop()

OUTPUT



Share
Tweet
Pin
Share
No Comments
Python TKinter Text Editor Program



INPUT

from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from tkinter.font import Font
from tkinter.scrolledtext import *
import file_menu
import edit_menu
import format_menu
import help_menu

root = Tk()

root.title("Text Editor-Untiltled")
root.geometry("300x250+300+300")
root.minsize(width=400, height=400)

text = ScrolledText(root, state='normal', height=400, width=400, wrap='word', pady=2, padx=3, undo=True)
text.pack(fill=Y, expand=1)
text.focus_set()

menubar = Menu(root)

file_menu.main(root, text, menubar)
edit_menu.main(root, text, menubar)
format_menu.main(root, text, menubar)
help_menu.main(root, text, menubar)
root.mainloop()

OUTPUT




Share
Tweet
Pin
Share
No Comments
Python Simple Calculator Program With TKinter Calculator




INPUT

from tkinter import Tk, Label, Button, Entry


class Root(Tk):
    def __init__(self):
        super().__init__()
        self.title_label = Label(self, text="A Simple Calculator :)")
        self.title_label.pack()
        self.entry = Entry(self)
        self.entry.pack()
        self.entry.insert(0, "1+2")
        self.label = Label(self, text="")
        self.label.pack()
        self.button = Button(self, text="Compute", command=self.onclick)
        self.button.pack()

    def onclick(self):
        self.label.configure(text=str(eval(self.entry.get())))


root = Root()
root.mainloop()

OUTPUT



Share
Tweet
Pin
Share
No Comments
Two matrices and print the product for the same.


INPUT

public class Matrix1{
public static void main(String args[]){   
int a[][]={{1,1,1},{2,2,2},{3,3,3}}; 
int b[][]={{1,1,1},{2,2,2},{3,3,3}};     
int c[][]=new int[3][3];   
for(int i=0;i<3;i++){ 
for(int j=0;j<3;j++){ 
c[i][j]=0;   
for(int k=0;k<3;k++)   
{   
c[i][j]+=a[i][k]*b[k][j];   
}
System.out.print(c[i][j]+" "); 
}
System.out.println(); 
} 
}}

OUTPUT



Share
Tweet
Pin
Share
No Comments

Add two matrices and print the resultant matrix.


INPUT

public class Matrix{
public static void main(String args[]){ 
int a[][]={{1,3,4},{2,4,3},{3,4,5}}; 
int b[][]={{1,3,4},{2,4,3},{1,2,4}};   
int c[][]=new int[3][3];   
for(int i=0;i<3;i++){ 
for(int j=0;j<3;j++){ 
c[i][j]=a[i][j]+b[i][j]; 
System.out.print(c[i][j]+" "); 
} 
System.out.println(); 
} 
}}

OUTPUT



Share
Tweet
Pin
Share
No Comments
Multiple Inheritance.


INPUT

interface Car
{
    int speed=60;
    public void distanceTravelled();
}
interface Bus
{
    int distance=100;
    public void speed();
}
public class Vehicle implements Car,Bus
{
    int distanceTravelled;
    int averageSpeed;
    public void distanceTravelled()
    {
        distanceTravelled=speed*distance;
        System.out.println("Total Distance Travelled is : "+distanceTravelled);
    }
    public void speed()
    {
        int averageSpeed=distanceTravelled/speed;
        System.out.println("Average Speed maintained is : "+averageSpeed);
    }
    public static void main(String args[])
    {
        Vehicle v1=new Vehicle();
        v1.distanceTravelled();
        v1.speed();
    }
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
Method Overriding



INPUT

class Human{
 
   public void eat()
   {
      System.out.println("Human is eating");
   }
}
class Boy extends Human{
 
   public void eat(){
      System.out.println("Boy is eating");
   }
   public static void main( String args[]) {
      Boy obj = new Boy();
   
      obj.eat();
   }
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
Single Level Inheritance. 


INPUT

class Single{
 static int num1=10;
 static int num2=5;
}

class Main extends Single{
 public static void main(String[] args){
 int num3=2;
 int result=num1+num2+num3;
 System.out.println("Result of child class is "+result);
 }
}

OUTPUT



Share
Tweet
Pin
Share
No Comments
Newer Posts
Older Posts

About me

Labels

  • C Programming
  • Java Programming
  • Python Programming
  • Software Engineering

recent posts

Sponsor

Facebook

Blog Archive

  • ▼  2020 (39)
    • ►  April (11)
    • ▼  March (28)
      • Basic Building Blocks Of The C Programming | VCMIT
      • Hello World Example In C Programming | VCMIT
      • Applications Of C Programming | Audience & Prerequ...
      • What Is C Programming? | Why To Learn C Programmin...
      • Draw The Moving Car On The Screen Program In C | V...
      • Develop The Program For The DDA Line Drawing Algor...
      • Bresenham’s Line Drawing Algorithm Program In C | ...
      • Create House Like Structure Perform Operations Pro...
      • Perform 2D Rotation On A Given Object Program In C...
      • Perform Smiling Face Animation Using Graphic Funct...
      • Draw A Simple Hut On The Screen Program In C | VCMIT
      • Write A Program To Fill A Circle Using Flood Fill ...
      • Write A Program To Implement Liang - Barsky Line C...
      • Draw The Walking Man On The Screen Program In C | ...
      • Drawing Different Shapes Program In C | BGI | VCMIT
      • Moving Fish Program In C| BGI | VCMIT
      • Python Turtle Python Logo Program | Turtle | VCMIT
      • Python TKinter Theme Program | TKinter | VCMIT
      • Python TKinter Text Editor Program | TKinter | VCMIT
      • Python Simple Calculator Program | TKinter Calcula...
      • Write a java program for multiplying two matrices ...
      • Write a java program to add two matrices and print...
      • Write a java program to implement multiple inherit...
      • Write a java program to implement method overridin...
      • Write a java program to implement single level inh...
      • Write a java program to demonstrate the implementa...
      • Designed a class that demonstrates the use of cons...
      • Designed a class SortData that contains the method...

Popular Posts

  • Python Turtle Python Logo Program | Turtle | VCMIT
    Turtle Python Logo Program INPUT import turtle l1 = [[0.0, -238.0], [92.6, -219.3], [168.3, -168.3], [219.3, -92.6], [238.0, 0.0], [219.3, 9...
  • Designed a class SortData that contains the method asec() and desc(). | VCMIT
    The Method asec() And desc(). INPUT import java.util.*; class prac4A { Scanner input=new Scanner(System.in); int num,i; int arr[]; int temp=...
  • Types Of Software | VCMIT
    Types Of Softwares The two main types of software are system software and application software. System software is a type of computer progra...
  • Software Engineering - Agile Model | VCMIT
    Agile Model The meaning of Agile is swift or versatile."Agile process model" refers to a software development approach based on it...
  • Designed a class that demonstrates the use of constructor and destructor. | VCMIT
    Constructor And Destructor. INPUT class Square{ int width,height; Square( int a , int b){ width = a; height = b; } int area(){ return width ...
  • Why Software Engineering is Popular? | VCMIT
    Why Software Engineering is Popular? Here are important reasons behind the popularity of software engineering: Large software – In our real...
  • What is Software Engineering? | VCMIT
    What is Software Engineering? Software engineering is defined as a process of analyzing user requirements and then designing, building, and ...
  • 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() #defi...
  • Software Engineering - RAD (Rapid Application Development) Model | VCMIT
    RAD (Rapid Application Development) Model RAD is a linear sequential software development process model that emphasizes a concise developmen...
  • 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...

Created with by ThemeXpose | Copy Blogger Themes